#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 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);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
130 ms |
202568 KB |
Output is correct |
2 |
Correct |
132 ms |
202640 KB |
Output is correct |
3 |
Correct |
152 ms |
205856 KB |
Output is correct |
4 |
Correct |
139 ms |
207756 KB |
Output is correct |
5 |
Correct |
120 ms |
202200 KB |
Output is correct |
6 |
Correct |
116 ms |
202196 KB |
Output is correct |
7 |
Correct |
152 ms |
208168 KB |
Output is correct |
8 |
Correct |
152 ms |
206172 KB |
Output is correct |
9 |
Correct |
138 ms |
202720 KB |
Output is correct |
10 |
Correct |
145 ms |
206008 KB |
Output is correct |
11 |
Correct |
146 ms |
204816 KB |
Output is correct |
12 |
Correct |
140 ms |
202760 KB |
Output is correct |
13 |
Correct |
139 ms |
203204 KB |
Output is correct |
14 |
Correct |
152 ms |
203204 KB |
Output is correct |
15 |
Correct |
134 ms |
204256 KB |
Output is correct |
16 |
Correct |
138 ms |
203284 KB |
Output is correct |
17 |
Correct |
128 ms |
202436 KB |
Output is correct |
18 |
Correct |
136 ms |
202660 KB |
Output is correct |
19 |
Correct |
113 ms |
202240 KB |
Output is correct |
20 |
Correct |
118 ms |
202440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
130 ms |
202568 KB |
Output is correct |
2 |
Correct |
132 ms |
202640 KB |
Output is correct |
3 |
Correct |
152 ms |
205856 KB |
Output is correct |
4 |
Correct |
139 ms |
207756 KB |
Output is correct |
5 |
Correct |
120 ms |
202200 KB |
Output is correct |
6 |
Correct |
116 ms |
202196 KB |
Output is correct |
7 |
Correct |
152 ms |
208168 KB |
Output is correct |
8 |
Correct |
152 ms |
206172 KB |
Output is correct |
9 |
Correct |
138 ms |
202720 KB |
Output is correct |
10 |
Correct |
145 ms |
206008 KB |
Output is correct |
11 |
Correct |
146 ms |
204816 KB |
Output is correct |
12 |
Correct |
140 ms |
202760 KB |
Output is correct |
13 |
Correct |
139 ms |
203204 KB |
Output is correct |
14 |
Correct |
152 ms |
203204 KB |
Output is correct |
15 |
Correct |
134 ms |
204256 KB |
Output is correct |
16 |
Correct |
138 ms |
203284 KB |
Output is correct |
17 |
Correct |
128 ms |
202436 KB |
Output is correct |
18 |
Correct |
136 ms |
202660 KB |
Output is correct |
19 |
Correct |
113 ms |
202240 KB |
Output is correct |
20 |
Correct |
118 ms |
202440 KB |
Output is correct |
21 |
Incorrect |
114 ms |
202300 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1086 ms |
203420 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
183 ms |
202660 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
130 ms |
202568 KB |
Output is correct |
2 |
Correct |
132 ms |
202640 KB |
Output is correct |
3 |
Correct |
152 ms |
205856 KB |
Output is correct |
4 |
Correct |
139 ms |
207756 KB |
Output is correct |
5 |
Correct |
120 ms |
202200 KB |
Output is correct |
6 |
Correct |
116 ms |
202196 KB |
Output is correct |
7 |
Correct |
152 ms |
208168 KB |
Output is correct |
8 |
Correct |
152 ms |
206172 KB |
Output is correct |
9 |
Correct |
138 ms |
202720 KB |
Output is correct |
10 |
Correct |
145 ms |
206008 KB |
Output is correct |
11 |
Correct |
146 ms |
204816 KB |
Output is correct |
12 |
Correct |
140 ms |
202760 KB |
Output is correct |
13 |
Correct |
139 ms |
203204 KB |
Output is correct |
14 |
Correct |
152 ms |
203204 KB |
Output is correct |
15 |
Correct |
134 ms |
204256 KB |
Output is correct |
16 |
Correct |
138 ms |
203284 KB |
Output is correct |
17 |
Correct |
128 ms |
202436 KB |
Output is correct |
18 |
Correct |
136 ms |
202660 KB |
Output is correct |
19 |
Correct |
113 ms |
202240 KB |
Output is correct |
20 |
Correct |
118 ms |
202440 KB |
Output is correct |
21 |
Execution timed out |
1086 ms |
203420 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
133 ms |
202560 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
130 ms |
202568 KB |
Output is correct |
2 |
Correct |
132 ms |
202640 KB |
Output is correct |
3 |
Correct |
152 ms |
205856 KB |
Output is correct |
4 |
Correct |
139 ms |
207756 KB |
Output is correct |
5 |
Correct |
120 ms |
202200 KB |
Output is correct |
6 |
Correct |
116 ms |
202196 KB |
Output is correct |
7 |
Correct |
152 ms |
208168 KB |
Output is correct |
8 |
Correct |
152 ms |
206172 KB |
Output is correct |
9 |
Correct |
138 ms |
202720 KB |
Output is correct |
10 |
Correct |
145 ms |
206008 KB |
Output is correct |
11 |
Correct |
146 ms |
204816 KB |
Output is correct |
12 |
Correct |
140 ms |
202760 KB |
Output is correct |
13 |
Correct |
139 ms |
203204 KB |
Output is correct |
14 |
Correct |
152 ms |
203204 KB |
Output is correct |
15 |
Correct |
134 ms |
204256 KB |
Output is correct |
16 |
Correct |
138 ms |
203284 KB |
Output is correct |
17 |
Correct |
128 ms |
202436 KB |
Output is correct |
18 |
Correct |
136 ms |
202660 KB |
Output is correct |
19 |
Correct |
113 ms |
202240 KB |
Output is correct |
20 |
Correct |
118 ms |
202440 KB |
Output is correct |
21 |
Incorrect |
114 ms |
202300 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
130 ms |
202568 KB |
Output is correct |
2 |
Correct |
132 ms |
202640 KB |
Output is correct |
3 |
Correct |
152 ms |
205856 KB |
Output is correct |
4 |
Correct |
139 ms |
207756 KB |
Output is correct |
5 |
Correct |
120 ms |
202200 KB |
Output is correct |
6 |
Correct |
116 ms |
202196 KB |
Output is correct |
7 |
Correct |
152 ms |
208168 KB |
Output is correct |
8 |
Correct |
152 ms |
206172 KB |
Output is correct |
9 |
Correct |
138 ms |
202720 KB |
Output is correct |
10 |
Correct |
145 ms |
206008 KB |
Output is correct |
11 |
Correct |
146 ms |
204816 KB |
Output is correct |
12 |
Correct |
140 ms |
202760 KB |
Output is correct |
13 |
Correct |
139 ms |
203204 KB |
Output is correct |
14 |
Correct |
152 ms |
203204 KB |
Output is correct |
15 |
Correct |
134 ms |
204256 KB |
Output is correct |
16 |
Correct |
138 ms |
203284 KB |
Output is correct |
17 |
Correct |
128 ms |
202436 KB |
Output is correct |
18 |
Correct |
136 ms |
202660 KB |
Output is correct |
19 |
Correct |
113 ms |
202240 KB |
Output is correct |
20 |
Correct |
118 ms |
202440 KB |
Output is correct |
21 |
Incorrect |
114 ms |
202300 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |