【CSP】201809-2 买菜

#include <iostream>
#include <cstdio>
using namespace std;
int t[1000010];
int n, x, y, mx = 0, cnt = 0;

int main(){
    cin >> n;
    for (int _ = 0; _ < 2*n; _++){
        cin >> x >> y;
        if (y > mx) mx = y;
        for (int i = x; i < y; i++) t[i] += 1;
    }
    for (int i = 1; i <= mx; i++) if (t[i] == 2) cnt++;
    cout << cnt;
    return 0;
}
上一篇:Trie前缀树原理


下一篇:Leetcode 528