#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define FOR(i,a,b) for(int i = (a) ; i <= (b) ; i++)
#define FORE(i,a,b) for(int i = (a) ; i >= (b) ; i--)
#define par pair<int , int>
#define ll long long
#define int long long
using namespace std;
const int N = 2e5+10;
const int INF = INT_MAX;
const int mod = 1e9+7;
int n,sum[N],m,Q;
pair<int,int> q[N],a[N];
set<pair<int,int>> s;
int ans[N],kq[N];
vector<pair<int,int>> pos;
int get_sum(int l, int r) {
return sum[r] - sum[l-1];
}
int Find(int x) {
int l = 1;
int r = Q;
int res = r+1;
while(l <= r) {
int mid = l + r >> 1;
if(q[mid].first >= x) {
res = mid;
r = mid-1;
}
else {
l = mid+1;
}
}
return res;
}
void update(int i, int val) {
if(i == 0) {
return;
}
kq[0] += val;
kq[i+1] -= val;
}
main()
{
if (fopen("inspections.inp", "r")) {
freopen("inspections.inp", "r", stdin);
freopen("inspections.out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> Q;
for(int i = 1 ; i <= m ; i++) {
cin >> a[i].first >> a[i].second;
sum[i] = sum[i-1] + (a[i].second-a[i].first+1);
}
for(int i = 1 ; i <= Q ; i++) {
cin >> q[i].first;
q[i].second = i;
}
sort(q+1,q+Q+1);
s.insert({0,0});
s.insert({n+1,0});
for(int i = 1 ; i <= m ; i++) {
int l = a[i].first;
int r = a[i].second;
int L = l;
auto u = s.upper_bound({l,INF});
u--;
auto v = s.upper_bound({r,INF});
if(v == s.end()) {
v--;
}
pos.clear();
for(auto it = u ; it != v ; it++) {
int id = ((*it).second);
pos.push_back({(*it).first,(*it).second});
auto hihi = it;
hihi++;
if(id != 0) {
int val = get_sum(id,i-1)-(l-a[id].first)+(l-L);
int x = Find(val);
int R = min(r,((*hihi).first-1));
update(x-1,R-l+1);
}
l = ((*hihi).first);
}
pos.push_back({(*v).first,(*v).second});
int len = pos.size()-1;
for(int p = 1 ; p < len ; p++) {
s.erase({pos[p].first,pos[p].second});
}
s.erase(u);
if(r+1 < pos[len].first) {
s.insert({r+1,pos[len-1].second});
}
if(pos[0].first < L) {
s.insert({pos[0].first,pos[0].second});
}
s.insert({L,i});
}
for(int i = 1 ; i <= Q ; i++) {
kq[i] += kq[i-1];
ans[q[i].second] = kq[i];
}
for(int i = 1 ; i <= Q ; i++) {
cout << ans[i] << " ";
}
return 0;
}
Compilation message
Main.cpp: In function 'long long int Find(long long int)':
Main.cpp:32:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
32 | int mid = l + r >> 1;
| ~~^~~
Main.cpp: At global scope:
Main.cpp:52:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
52 | main()
| ^~~~
Main.cpp: In function 'int main()':
Main.cpp:55:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
55 | freopen("inspections.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
56 | freopen("inspections.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8664 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8664 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
49 ms |
12628 KB |
Output is correct |
14 |
Correct |
38 ms |
12624 KB |
Output is correct |
15 |
Correct |
40 ms |
12704 KB |
Output is correct |
16 |
Correct |
40 ms |
13140 KB |
Output is correct |
17 |
Correct |
40 ms |
12632 KB |
Output is correct |
18 |
Correct |
40 ms |
12628 KB |
Output is correct |
19 |
Correct |
44 ms |
13436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
1 ms |
8664 KB |
Output is correct |
3 |
Correct |
40 ms |
12628 KB |
Output is correct |
4 |
Correct |
53 ms |
13332 KB |
Output is correct |
5 |
Correct |
130 ms |
16208 KB |
Output is correct |
6 |
Correct |
94 ms |
15948 KB |
Output is correct |
7 |
Correct |
89 ms |
15380 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8664 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
49 ms |
12628 KB |
Output is correct |
14 |
Correct |
38 ms |
12624 KB |
Output is correct |
15 |
Correct |
40 ms |
12704 KB |
Output is correct |
16 |
Correct |
40 ms |
13140 KB |
Output is correct |
17 |
Correct |
40 ms |
12632 KB |
Output is correct |
18 |
Correct |
40 ms |
12628 KB |
Output is correct |
19 |
Correct |
44 ms |
13436 KB |
Output is correct |
20 |
Correct |
42 ms |
13904 KB |
Output is correct |
21 |
Correct |
39 ms |
13140 KB |
Output is correct |
22 |
Correct |
41 ms |
13908 KB |
Output is correct |
23 |
Correct |
38 ms |
13140 KB |
Output is correct |
24 |
Correct |
39 ms |
12856 KB |
Output is correct |
25 |
Correct |
46 ms |
13396 KB |
Output is correct |
26 |
Correct |
41 ms |
13912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8664 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
49 ms |
12628 KB |
Output is correct |
14 |
Correct |
38 ms |
12624 KB |
Output is correct |
15 |
Correct |
40 ms |
12704 KB |
Output is correct |
16 |
Correct |
40 ms |
13140 KB |
Output is correct |
17 |
Correct |
40 ms |
12632 KB |
Output is correct |
18 |
Correct |
40 ms |
12628 KB |
Output is correct |
19 |
Correct |
44 ms |
13436 KB |
Output is correct |
20 |
Correct |
1 ms |
8536 KB |
Output is correct |
21 |
Correct |
1 ms |
8664 KB |
Output is correct |
22 |
Correct |
40 ms |
12628 KB |
Output is correct |
23 |
Correct |
53 ms |
13332 KB |
Output is correct |
24 |
Correct |
130 ms |
16208 KB |
Output is correct |
25 |
Correct |
94 ms |
15948 KB |
Output is correct |
26 |
Correct |
89 ms |
15380 KB |
Output is correct |
27 |
Correct |
1 ms |
8540 KB |
Output is correct |
28 |
Correct |
1 ms |
8664 KB |
Output is correct |
29 |
Correct |
42 ms |
13904 KB |
Output is correct |
30 |
Correct |
39 ms |
13140 KB |
Output is correct |
31 |
Correct |
41 ms |
13908 KB |
Output is correct |
32 |
Correct |
38 ms |
13140 KB |
Output is correct |
33 |
Correct |
39 ms |
12856 KB |
Output is correct |
34 |
Correct |
46 ms |
13396 KB |
Output is correct |
35 |
Correct |
41 ms |
13912 KB |
Output is correct |
36 |
Correct |
222 ms |
16900 KB |
Output is correct |
37 |
Correct |
208 ms |
17004 KB |
Output is correct |
38 |
Correct |
154 ms |
16788 KB |
Output is correct |
39 |
Correct |
131 ms |
16404 KB |
Output is correct |
40 |
Correct |
187 ms |
16720 KB |
Output is correct |
41 |
Correct |
230 ms |
23320 KB |
Output is correct |
42 |
Correct |
221 ms |
24460 KB |
Output is correct |
43 |
Correct |
260 ms |
33808 KB |
Output is correct |
44 |
Correct |
242 ms |
32956 KB |
Output is correct |
45 |
Correct |
230 ms |
16212 KB |
Output is correct |
46 |
Correct |
344 ms |
18260 KB |
Output is correct |
47 |
Correct |
246 ms |
18516 KB |
Output is correct |
48 |
Correct |
188 ms |
17352 KB |
Output is correct |