#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 2.5e5 + 10;
const int MOD = 1e9 + 7;
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
int u = uniform_int_distribution<int>(x, y)(rng);
return u;
}
int bm(int b, int p) { // bigmod
if(p==0) return 1;
int r = bm(b, p/2);
if(p&1) return (((r*r) % MOD) * b) % MOD;
return (r*r) % MOD;
}
int N, M, Q;
deque<pair<int, int> > ok[MAXN];
void join(int l, int r, int c, int k) {
for(int i=l; i<=r; i++) ok[i].push_back({c, k});
}
void leave(int l, int r, int k) {
for(int i=l; i<=r; i++) {
int m = k;
while(ok[i].size() && m > 0) {
pair<int, int> f = ok[i].front();
if(m >= f.second) {
m -= f.second;
ok[i].pop_front();
}
else {
f.second -= m;
ok[i].pop_front();
ok[i].push_front(f);
break;
}
}
}
}
int service(int a, int b) {
stack<pair<int, int> > st;
int ans = 0;
while(ok[a].size()) {
pair<int, int> f = ok[a].front();
if(b <= f.second) {
ans = f.first;
break;
}
else b -= f.second;
st.push(f);
ok[a].pop_front();
}
while(st.size()) {
ok[a].push_front(st.top());
st.pop();
}
return ans;
}
void solve(int tc) {
cin >> N >> M >> Q;
while(Q--) {
int t;
cin >> t;
if(t == 1) {
int l, r, c, k;
cin >> l >> r >> c >> k;
join(l, r, c, k);
}
else if(t == 2) {
int l, r, k;
cin >> l >> r >> k;
leave(l, r, k);
}
else {
int a, b;
cin >> a >> b;
cout << service(a, b) << "\n";
}
}
}
int32_t main(){
ios::sync_with_stdio(0); cin.tie(0);
int t = 1; //cin >> t;
for(int i=1; i<=t; i++) {
solve(i);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
132 ms |
169024 KB |
Output is correct |
2 |
Correct |
116 ms |
169324 KB |
Output is correct |
3 |
Correct |
121 ms |
175940 KB |
Output is correct |
4 |
Correct |
146 ms |
179504 KB |
Output is correct |
5 |
Correct |
100 ms |
168624 KB |
Output is correct |
6 |
Correct |
101 ms |
168580 KB |
Output is correct |
7 |
Correct |
147 ms |
181172 KB |
Output is correct |
8 |
Correct |
140 ms |
176784 KB |
Output is correct |
9 |
Correct |
132 ms |
169360 KB |
Output is correct |
10 |
Correct |
155 ms |
176252 KB |
Output is correct |
11 |
Correct |
154 ms |
173356 KB |
Output is correct |
12 |
Correct |
141 ms |
169560 KB |
Output is correct |
13 |
Correct |
121 ms |
169556 KB |
Output is correct |
14 |
Correct |
118 ms |
170612 KB |
Output is correct |
15 |
Correct |
138 ms |
171576 KB |
Output is correct |
16 |
Correct |
123 ms |
170588 KB |
Output is correct |
17 |
Correct |
132 ms |
168980 KB |
Output is correct |
18 |
Correct |
133 ms |
169092 KB |
Output is correct |
19 |
Correct |
105 ms |
168636 KB |
Output is correct |
20 |
Correct |
106 ms |
168644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
132 ms |
169024 KB |
Output is correct |
2 |
Correct |
116 ms |
169324 KB |
Output is correct |
3 |
Correct |
121 ms |
175940 KB |
Output is correct |
4 |
Correct |
146 ms |
179504 KB |
Output is correct |
5 |
Correct |
100 ms |
168624 KB |
Output is correct |
6 |
Correct |
101 ms |
168580 KB |
Output is correct |
7 |
Correct |
147 ms |
181172 KB |
Output is correct |
8 |
Correct |
140 ms |
176784 KB |
Output is correct |
9 |
Correct |
132 ms |
169360 KB |
Output is correct |
10 |
Correct |
155 ms |
176252 KB |
Output is correct |
11 |
Correct |
154 ms |
173356 KB |
Output is correct |
12 |
Correct |
141 ms |
169560 KB |
Output is correct |
13 |
Correct |
121 ms |
169556 KB |
Output is correct |
14 |
Correct |
118 ms |
170612 KB |
Output is correct |
15 |
Correct |
138 ms |
171576 KB |
Output is correct |
16 |
Correct |
123 ms |
170588 KB |
Output is correct |
17 |
Correct |
132 ms |
168980 KB |
Output is correct |
18 |
Correct |
133 ms |
169092 KB |
Output is correct |
19 |
Correct |
105 ms |
168636 KB |
Output is correct |
20 |
Correct |
106 ms |
168644 KB |
Output is correct |
21 |
Correct |
156 ms |
169368 KB |
Output is correct |
22 |
Correct |
128 ms |
169464 KB |
Output is correct |
23 |
Correct |
126 ms |
175928 KB |
Output is correct |
24 |
Correct |
142 ms |
179628 KB |
Output is correct |
25 |
Correct |
98 ms |
168632 KB |
Output is correct |
26 |
Correct |
96 ms |
168556 KB |
Output is correct |
27 |
Correct |
127 ms |
180660 KB |
Output is correct |
28 |
Correct |
127 ms |
177476 KB |
Output is correct |
29 |
Correct |
127 ms |
171188 KB |
Output is correct |
30 |
Correct |
126 ms |
175784 KB |
Output is correct |
31 |
Correct |
127 ms |
173264 KB |
Output is correct |
32 |
Correct |
122 ms |
169296 KB |
Output is correct |
33 |
Correct |
128 ms |
169540 KB |
Output is correct |
34 |
Correct |
132 ms |
171720 KB |
Output is correct |
35 |
Correct |
123 ms |
170116 KB |
Output is correct |
36 |
Correct |
135 ms |
170576 KB |
Output is correct |
37 |
Correct |
96 ms |
168576 KB |
Output is correct |
38 |
Correct |
101 ms |
168652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1098 ms |
169884 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1099 ms |
265824 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
132 ms |
169024 KB |
Output is correct |
2 |
Correct |
116 ms |
169324 KB |
Output is correct |
3 |
Correct |
121 ms |
175940 KB |
Output is correct |
4 |
Correct |
146 ms |
179504 KB |
Output is correct |
5 |
Correct |
100 ms |
168624 KB |
Output is correct |
6 |
Correct |
101 ms |
168580 KB |
Output is correct |
7 |
Correct |
147 ms |
181172 KB |
Output is correct |
8 |
Correct |
140 ms |
176784 KB |
Output is correct |
9 |
Correct |
132 ms |
169360 KB |
Output is correct |
10 |
Correct |
155 ms |
176252 KB |
Output is correct |
11 |
Correct |
154 ms |
173356 KB |
Output is correct |
12 |
Correct |
141 ms |
169560 KB |
Output is correct |
13 |
Correct |
121 ms |
169556 KB |
Output is correct |
14 |
Correct |
118 ms |
170612 KB |
Output is correct |
15 |
Correct |
138 ms |
171576 KB |
Output is correct |
16 |
Correct |
123 ms |
170588 KB |
Output is correct |
17 |
Correct |
132 ms |
168980 KB |
Output is correct |
18 |
Correct |
133 ms |
169092 KB |
Output is correct |
19 |
Correct |
105 ms |
168636 KB |
Output is correct |
20 |
Correct |
106 ms |
168644 KB |
Output is correct |
21 |
Execution timed out |
1098 ms |
169884 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
444 ms |
524292 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
132 ms |
169024 KB |
Output is correct |
2 |
Correct |
116 ms |
169324 KB |
Output is correct |
3 |
Correct |
121 ms |
175940 KB |
Output is correct |
4 |
Correct |
146 ms |
179504 KB |
Output is correct |
5 |
Correct |
100 ms |
168624 KB |
Output is correct |
6 |
Correct |
101 ms |
168580 KB |
Output is correct |
7 |
Correct |
147 ms |
181172 KB |
Output is correct |
8 |
Correct |
140 ms |
176784 KB |
Output is correct |
9 |
Correct |
132 ms |
169360 KB |
Output is correct |
10 |
Correct |
155 ms |
176252 KB |
Output is correct |
11 |
Correct |
154 ms |
173356 KB |
Output is correct |
12 |
Correct |
141 ms |
169560 KB |
Output is correct |
13 |
Correct |
121 ms |
169556 KB |
Output is correct |
14 |
Correct |
118 ms |
170612 KB |
Output is correct |
15 |
Correct |
138 ms |
171576 KB |
Output is correct |
16 |
Correct |
123 ms |
170588 KB |
Output is correct |
17 |
Correct |
132 ms |
168980 KB |
Output is correct |
18 |
Correct |
133 ms |
169092 KB |
Output is correct |
19 |
Correct |
105 ms |
168636 KB |
Output is correct |
20 |
Correct |
106 ms |
168644 KB |
Output is correct |
21 |
Correct |
156 ms |
169368 KB |
Output is correct |
22 |
Correct |
128 ms |
169464 KB |
Output is correct |
23 |
Correct |
126 ms |
175928 KB |
Output is correct |
24 |
Correct |
142 ms |
179628 KB |
Output is correct |
25 |
Correct |
98 ms |
168632 KB |
Output is correct |
26 |
Correct |
96 ms |
168556 KB |
Output is correct |
27 |
Correct |
127 ms |
180660 KB |
Output is correct |
28 |
Correct |
127 ms |
177476 KB |
Output is correct |
29 |
Correct |
127 ms |
171188 KB |
Output is correct |
30 |
Correct |
126 ms |
175784 KB |
Output is correct |
31 |
Correct |
127 ms |
173264 KB |
Output is correct |
32 |
Correct |
122 ms |
169296 KB |
Output is correct |
33 |
Correct |
128 ms |
169540 KB |
Output is correct |
34 |
Correct |
132 ms |
171720 KB |
Output is correct |
35 |
Correct |
123 ms |
170116 KB |
Output is correct |
36 |
Correct |
135 ms |
170576 KB |
Output is correct |
37 |
Correct |
96 ms |
168576 KB |
Output is correct |
38 |
Correct |
101 ms |
168652 KB |
Output is correct |
39 |
Execution timed out |
1098 ms |
169884 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
132 ms |
169024 KB |
Output is correct |
2 |
Correct |
116 ms |
169324 KB |
Output is correct |
3 |
Correct |
121 ms |
175940 KB |
Output is correct |
4 |
Correct |
146 ms |
179504 KB |
Output is correct |
5 |
Correct |
100 ms |
168624 KB |
Output is correct |
6 |
Correct |
101 ms |
168580 KB |
Output is correct |
7 |
Correct |
147 ms |
181172 KB |
Output is correct |
8 |
Correct |
140 ms |
176784 KB |
Output is correct |
9 |
Correct |
132 ms |
169360 KB |
Output is correct |
10 |
Correct |
155 ms |
176252 KB |
Output is correct |
11 |
Correct |
154 ms |
173356 KB |
Output is correct |
12 |
Correct |
141 ms |
169560 KB |
Output is correct |
13 |
Correct |
121 ms |
169556 KB |
Output is correct |
14 |
Correct |
118 ms |
170612 KB |
Output is correct |
15 |
Correct |
138 ms |
171576 KB |
Output is correct |
16 |
Correct |
123 ms |
170588 KB |
Output is correct |
17 |
Correct |
132 ms |
168980 KB |
Output is correct |
18 |
Correct |
133 ms |
169092 KB |
Output is correct |
19 |
Correct |
105 ms |
168636 KB |
Output is correct |
20 |
Correct |
106 ms |
168644 KB |
Output is correct |
21 |
Correct |
156 ms |
169368 KB |
Output is correct |
22 |
Correct |
128 ms |
169464 KB |
Output is correct |
23 |
Correct |
126 ms |
175928 KB |
Output is correct |
24 |
Correct |
142 ms |
179628 KB |
Output is correct |
25 |
Correct |
98 ms |
168632 KB |
Output is correct |
26 |
Correct |
96 ms |
168556 KB |
Output is correct |
27 |
Correct |
127 ms |
180660 KB |
Output is correct |
28 |
Correct |
127 ms |
177476 KB |
Output is correct |
29 |
Correct |
127 ms |
171188 KB |
Output is correct |
30 |
Correct |
126 ms |
175784 KB |
Output is correct |
31 |
Correct |
127 ms |
173264 KB |
Output is correct |
32 |
Correct |
122 ms |
169296 KB |
Output is correct |
33 |
Correct |
128 ms |
169540 KB |
Output is correct |
34 |
Correct |
132 ms |
171720 KB |
Output is correct |
35 |
Correct |
123 ms |
170116 KB |
Output is correct |
36 |
Correct |
135 ms |
170576 KB |
Output is correct |
37 |
Correct |
96 ms |
168576 KB |
Output is correct |
38 |
Correct |
101 ms |
168652 KB |
Output is correct |
39 |
Execution timed out |
1098 ms |
169884 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |