#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXQ = 500000;
pair <int, pair <int, int> > zapr[MAXQ + 5];
map <int, int> opa;
int inv[MAXQ + 5];
ll ants[MAXQ + 5], sugar[MAXQ + 5], cop[MAXQ + 5];
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(0); cin.tie(0);
int quer, len;
cin >> quer >> len;
for (int i = 1; i <= quer; i++)
{
int typ, x, cnt;
cin >> typ >> x >> cnt;
zapr[i] = mp(typ, mp(x, cnt));
opa.insert(mp(x, 0));
}
int cnt = 0;
for (auto it = opa.begin(); it != opa.end(); it++)
{
cnt++;
inv[cnt] = it->x;
it->y = cnt;
}
for (int i = 1; i <= quer; i++) zapr[i].y.x = opa[zapr[i].y.x];
for (int i = 1; i <= quer; i++)
{
if (zapr[i].x == 1) ants[zapr[i].y.x] += zapr[i].y.y;
else sugar[zapr[i].y.x] += zapr[i].y.y;
for (int k = 1; k <= cnt; k++) cop[k] = ants[k];
int uk = 1;
ll ans = 0;
for (int k = 1; k <= cnt; k++)
{
if (sugar[k] == 0) continue;
while (uk <= cnt && (inv[k] - inv[uk] > len || cop[uk] == 0)) uk++;
ll ost = sugar[k];
while (uk <= cnt && ost > 0 && (inv[uk] - inv[k]) <= len)
{
ll tt = min(ost, cop[uk]);
ost -= tt;
cop[uk] -= tt;
ans += tt;
if (cop[uk] == 0) uk++;
}
}
cout << ans << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
15 ms |
468 KB |
Output is correct |
7 |
Correct |
12 ms |
468 KB |
Output is correct |
8 |
Correct |
4 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
340 KB |
Output is correct |
10 |
Correct |
40 ms |
688 KB |
Output is correct |
11 |
Correct |
44 ms |
704 KB |
Output is correct |
12 |
Correct |
44 ms |
688 KB |
Output is correct |
13 |
Correct |
48 ms |
696 KB |
Output is correct |
14 |
Correct |
31 ms |
544 KB |
Output is correct |
15 |
Correct |
35 ms |
688 KB |
Output is correct |
16 |
Correct |
18 ms |
596 KB |
Output is correct |
17 |
Correct |
18 ms |
596 KB |
Output is correct |
18 |
Correct |
9 ms |
596 KB |
Output is correct |
19 |
Correct |
39 ms |
700 KB |
Output is correct |
20 |
Correct |
9 ms |
596 KB |
Output is correct |
21 |
Correct |
45 ms |
596 KB |
Output is correct |
22 |
Correct |
9 ms |
600 KB |
Output is correct |
23 |
Correct |
47 ms |
596 KB |
Output is correct |
24 |
Correct |
25 ms |
648 KB |
Output is correct |
25 |
Correct |
45 ms |
676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Execution timed out |
4025 ms |
27376 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Execution timed out |
4091 ms |
20268 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
15 ms |
468 KB |
Output is correct |
7 |
Correct |
12 ms |
468 KB |
Output is correct |
8 |
Correct |
4 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
340 KB |
Output is correct |
10 |
Correct |
40 ms |
688 KB |
Output is correct |
11 |
Correct |
44 ms |
704 KB |
Output is correct |
12 |
Correct |
44 ms |
688 KB |
Output is correct |
13 |
Correct |
48 ms |
696 KB |
Output is correct |
14 |
Correct |
31 ms |
544 KB |
Output is correct |
15 |
Correct |
35 ms |
688 KB |
Output is correct |
16 |
Correct |
18 ms |
596 KB |
Output is correct |
17 |
Correct |
18 ms |
596 KB |
Output is correct |
18 |
Correct |
9 ms |
596 KB |
Output is correct |
19 |
Correct |
39 ms |
700 KB |
Output is correct |
20 |
Correct |
9 ms |
596 KB |
Output is correct |
21 |
Correct |
45 ms |
596 KB |
Output is correct |
22 |
Correct |
9 ms |
600 KB |
Output is correct |
23 |
Correct |
47 ms |
596 KB |
Output is correct |
24 |
Correct |
25 ms |
648 KB |
Output is correct |
25 |
Correct |
45 ms |
676 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Execution timed out |
4025 ms |
27376 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |