#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) begin(a),end(a)
const int mxN = 65010;
int n, m, q, tot[mxN], del[mxN];
vector<array<int,2>> shop[mxN];
void add(int i, int x, int v){
if(sz(shop[i]) and shop[i].back()[0]==x) shop[i].back()[1]+=v,tot[i]+=v;
else shop[i].pb({x,v+(sz(shop[i])?shop[i].back()[1]:0)}),tot[i]+=v;
}
void rem(int i, int v){
if(tot[i]<=v) del[i]+=tot[i], tot[i]=0;
else del[i]+=v, tot[i]-=v;
}
int get(int i, int v){
v+=del[i]; if(!sz(shop[i]) or shop[i].back()[1]<v) return 0;
int l = 0, r = sz(shop[i])-1;
while(l<r){
int mid = (l+r)/2;
if(shop[i][mid][1]<v) l=mid+1;
else r=mid;
}
return shop[i][l][0];
}
int32_t main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> m >> q;
while(q--){
int t, l, r, x, v; cin >> t;
if(t==1){
cin >> l >> r >> x >> v;
for(int i = l; i <= r; i++) add(i,x,v);
}
else if(t==2){
cin >> l >> r >> v;
for(int i = l; i <= r; i++) rem(i,v);
}
else cin >> x >> v, cout << get(x,v) << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4820 KB |
Output is correct |
2 |
Correct |
12 ms |
7604 KB |
Output is correct |
3 |
Correct |
12 ms |
8628 KB |
Output is correct |
4 |
Correct |
23 ms |
14716 KB |
Output is correct |
5 |
Correct |
2 ms |
1876 KB |
Output is correct |
6 |
Correct |
1 ms |
1876 KB |
Output is correct |
7 |
Correct |
17 ms |
10992 KB |
Output is correct |
8 |
Correct |
15 ms |
10760 KB |
Output is correct |
9 |
Correct |
16 ms |
10780 KB |
Output is correct |
10 |
Correct |
15 ms |
11480 KB |
Output is correct |
11 |
Correct |
18 ms |
11824 KB |
Output is correct |
12 |
Correct |
18 ms |
11200 KB |
Output is correct |
13 |
Correct |
21 ms |
16416 KB |
Output is correct |
14 |
Correct |
27 ms |
17992 KB |
Output is correct |
15 |
Correct |
18 ms |
9648 KB |
Output is correct |
16 |
Correct |
30 ms |
17812 KB |
Output is correct |
17 |
Correct |
9 ms |
6356 KB |
Output is correct |
18 |
Correct |
14 ms |
8824 KB |
Output is correct |
19 |
Correct |
2 ms |
2004 KB |
Output is correct |
20 |
Correct |
2 ms |
2004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4820 KB |
Output is correct |
2 |
Correct |
12 ms |
7604 KB |
Output is correct |
3 |
Correct |
12 ms |
8628 KB |
Output is correct |
4 |
Correct |
23 ms |
14716 KB |
Output is correct |
5 |
Correct |
2 ms |
1876 KB |
Output is correct |
6 |
Correct |
1 ms |
1876 KB |
Output is correct |
7 |
Correct |
17 ms |
10992 KB |
Output is correct |
8 |
Correct |
15 ms |
10760 KB |
Output is correct |
9 |
Correct |
16 ms |
10780 KB |
Output is correct |
10 |
Correct |
15 ms |
11480 KB |
Output is correct |
11 |
Correct |
18 ms |
11824 KB |
Output is correct |
12 |
Correct |
18 ms |
11200 KB |
Output is correct |
13 |
Correct |
21 ms |
16416 KB |
Output is correct |
14 |
Correct |
27 ms |
17992 KB |
Output is correct |
15 |
Correct |
18 ms |
9648 KB |
Output is correct |
16 |
Correct |
30 ms |
17812 KB |
Output is correct |
17 |
Correct |
9 ms |
6356 KB |
Output is correct |
18 |
Correct |
14 ms |
8824 KB |
Output is correct |
19 |
Correct |
2 ms |
2004 KB |
Output is correct |
20 |
Correct |
2 ms |
2004 KB |
Output is correct |
21 |
Incorrect |
2 ms |
1876 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
808 ms |
4572 KB |
Output is correct |
2 |
Correct |
606 ms |
6760 KB |
Output is correct |
3 |
Correct |
792 ms |
7152 KB |
Output is correct |
4 |
Correct |
807 ms |
7144 KB |
Output is correct |
5 |
Correct |
619 ms |
8688 KB |
Output is correct |
6 |
Correct |
668 ms |
8744 KB |
Output is correct |
7 |
Correct |
13 ms |
3028 KB |
Output is correct |
8 |
Correct |
22 ms |
3144 KB |
Output is correct |
9 |
Execution timed out |
1088 ms |
5552 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
3488 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4820 KB |
Output is correct |
2 |
Correct |
12 ms |
7604 KB |
Output is correct |
3 |
Correct |
12 ms |
8628 KB |
Output is correct |
4 |
Correct |
23 ms |
14716 KB |
Output is correct |
5 |
Correct |
2 ms |
1876 KB |
Output is correct |
6 |
Correct |
1 ms |
1876 KB |
Output is correct |
7 |
Correct |
17 ms |
10992 KB |
Output is correct |
8 |
Correct |
15 ms |
10760 KB |
Output is correct |
9 |
Correct |
16 ms |
10780 KB |
Output is correct |
10 |
Correct |
15 ms |
11480 KB |
Output is correct |
11 |
Correct |
18 ms |
11824 KB |
Output is correct |
12 |
Correct |
18 ms |
11200 KB |
Output is correct |
13 |
Correct |
21 ms |
16416 KB |
Output is correct |
14 |
Correct |
27 ms |
17992 KB |
Output is correct |
15 |
Correct |
18 ms |
9648 KB |
Output is correct |
16 |
Correct |
30 ms |
17812 KB |
Output is correct |
17 |
Correct |
9 ms |
6356 KB |
Output is correct |
18 |
Correct |
14 ms |
8824 KB |
Output is correct |
19 |
Correct |
2 ms |
2004 KB |
Output is correct |
20 |
Correct |
2 ms |
2004 KB |
Output is correct |
21 |
Correct |
808 ms |
4572 KB |
Output is correct |
22 |
Correct |
606 ms |
6760 KB |
Output is correct |
23 |
Correct |
792 ms |
7152 KB |
Output is correct |
24 |
Correct |
807 ms |
7144 KB |
Output is correct |
25 |
Correct |
619 ms |
8688 KB |
Output is correct |
26 |
Correct |
668 ms |
8744 KB |
Output is correct |
27 |
Correct |
13 ms |
3028 KB |
Output is correct |
28 |
Correct |
22 ms |
3144 KB |
Output is correct |
29 |
Execution timed out |
1088 ms |
5552 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
5460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4820 KB |
Output is correct |
2 |
Correct |
12 ms |
7604 KB |
Output is correct |
3 |
Correct |
12 ms |
8628 KB |
Output is correct |
4 |
Correct |
23 ms |
14716 KB |
Output is correct |
5 |
Correct |
2 ms |
1876 KB |
Output is correct |
6 |
Correct |
1 ms |
1876 KB |
Output is correct |
7 |
Correct |
17 ms |
10992 KB |
Output is correct |
8 |
Correct |
15 ms |
10760 KB |
Output is correct |
9 |
Correct |
16 ms |
10780 KB |
Output is correct |
10 |
Correct |
15 ms |
11480 KB |
Output is correct |
11 |
Correct |
18 ms |
11824 KB |
Output is correct |
12 |
Correct |
18 ms |
11200 KB |
Output is correct |
13 |
Correct |
21 ms |
16416 KB |
Output is correct |
14 |
Correct |
27 ms |
17992 KB |
Output is correct |
15 |
Correct |
18 ms |
9648 KB |
Output is correct |
16 |
Correct |
30 ms |
17812 KB |
Output is correct |
17 |
Correct |
9 ms |
6356 KB |
Output is correct |
18 |
Correct |
14 ms |
8824 KB |
Output is correct |
19 |
Correct |
2 ms |
2004 KB |
Output is correct |
20 |
Correct |
2 ms |
2004 KB |
Output is correct |
21 |
Incorrect |
2 ms |
1876 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4820 KB |
Output is correct |
2 |
Correct |
12 ms |
7604 KB |
Output is correct |
3 |
Correct |
12 ms |
8628 KB |
Output is correct |
4 |
Correct |
23 ms |
14716 KB |
Output is correct |
5 |
Correct |
2 ms |
1876 KB |
Output is correct |
6 |
Correct |
1 ms |
1876 KB |
Output is correct |
7 |
Correct |
17 ms |
10992 KB |
Output is correct |
8 |
Correct |
15 ms |
10760 KB |
Output is correct |
9 |
Correct |
16 ms |
10780 KB |
Output is correct |
10 |
Correct |
15 ms |
11480 KB |
Output is correct |
11 |
Correct |
18 ms |
11824 KB |
Output is correct |
12 |
Correct |
18 ms |
11200 KB |
Output is correct |
13 |
Correct |
21 ms |
16416 KB |
Output is correct |
14 |
Correct |
27 ms |
17992 KB |
Output is correct |
15 |
Correct |
18 ms |
9648 KB |
Output is correct |
16 |
Correct |
30 ms |
17812 KB |
Output is correct |
17 |
Correct |
9 ms |
6356 KB |
Output is correct |
18 |
Correct |
14 ms |
8824 KB |
Output is correct |
19 |
Correct |
2 ms |
2004 KB |
Output is correct |
20 |
Correct |
2 ms |
2004 KB |
Output is correct |
21 |
Incorrect |
2 ms |
1876 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |