#35447: _C++


11131039@stu.tshs.tp.edu.tw (林孟希)

學校 : 國立臺灣大學
編號 : 201083
來源 : [140.112.25.29]
最後登入時間 :
2025-09-26 16:05:38

一次一次覆蓋掉

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    cin>>n;
    long long a[1000000]={0};
    for(int i=0;i<n;i++)
    {
        int l,r;
        cin>>l>>r;
        for(int j=l;j<=l+(r-l-1);j++)
        {
            a[j]=1;
        }
    }
    int cnt=0;
    for(int i=0;i<1000000;i++)
    {
        if(a[i]==1)
        {
            cnt++;
        }
    }
    cout<<cnt;
}