#include<bits/stdc++.h>
#define pb push_back
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int maxn = 3e5 + 5;
int n, m, k;
vector<int> own[maxn];
ll need[maxn];
pair<ii, int> qs[maxn];
vector<pair<ii, int>> A[maxn];
vector<pair<ii, int>> A1[maxn];
int ans[maxn], ok[maxn];
ll fwt[maxn];
void update(int x, int v) {
x++;
for(;x < maxn;x += (x & -x)) fwt[x] += (ll)v;
}
ll query(int x) {
x++;
ll ret = 0;
for(;x > 0;x -= (x & -x)) ret += fwt[x];
return ret;
}
int main() {
scanf("%d %d", &n, &m);
for(int i = 0;i < m;i++) {
int x;scanf("%d", &x);x--;
own[x].pb(i);
}
for(int i = 0;i < n;i++) scanf("%lld", need + i);
scanf("%d", &k);
for(int i = 0;i < k;i++) {
int l, r, a;
scanf("%d %d %d", &l, &r, &a);
l--, r--;
qs[i] = {{l, r}, a};
}
for(int i = 0;i < n;i++) {
int mid = (k - 1) / 2;
A[mid].pb({{0, k - 1}, i});
}
while(true) {
for(int i = 0;i < maxn;i++) fwt[i] = 0;
int flag = 0;
for(int i = 0;i < k;i++) {
if(qs[i].x.x > qs[i].x.y) {
update(qs[i].x.x, qs[i].y);
update(m, -qs[i].y);
update(0, qs[i].y);
update(qs[i].x.y + 1, -qs[i].y);
} else {
update(qs[i].x.x, qs[i].y);
update(qs[i].x.y + 1, -qs[i].y);
}
for(pair<ii, int> p : A[i]) {
//cout << i << "->" << p.x.x << ' ' << p.x.y << " (" << p.y << ")\n";
if(p.x.x > p.x.y) {continue;}
flag = 1;
ll sum = 0;
for(int j : own[p.y]) sum += query(j);
//cout << sum << "\n";
pair<ii, int> p1 = p;
if(sum < need[p.y]) {
int mid = i + 1 + (p.x.y - i - 1) / 2;
p1.x.x = i + 1;
if(p1.x.x <= p1.x.y && mid >= 0 && mid < k) A1[mid].pb(p1);
}
if(sum >= need[p.y]) {
int mid = p.x.x + (i - 1 - p.x.x) / 2;
p1.x.y = i - 1;
if(p1.x.x <= p1.x.y && mid >= 0 && mid < k) A1[mid].pb(p1);
ans[p.y] = i + 1;
}
}
}
for(int i = 0;i < k;i++) A[i].clear(), A[i].shrink_to_fit(), A[i] = A1[i], A1[i].clear(), A1[i].shrink_to_fit();
if(!flag) {break;}
}
for(int i = 0;i < n;i++) {
if(!ans[i]) printf("NIE\n"); else printf("%d\n", ans[i]);
}
return 0;
}
Compilation message
met.cpp: In function 'int main()':
met.cpp:36:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
36 | scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
met.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
38 | int x;scanf("%d", &x);x--;
| ~~~~~^~~~~~~~~~
met.cpp:41:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | for(int i = 0;i < n;i++) scanf("%lld", need + i);
| ~~~~~^~~~~~~~~~~~~~~~~~
met.cpp:43:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | scanf("%d", &k);
| ~~~~~^~~~~~~~~~
met.cpp:46:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
46 | scanf("%d %d %d", &l, &r, &a);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
23764 KB |
Output is correct |
2 |
Correct |
14 ms |
23752 KB |
Output is correct |
3 |
Correct |
15 ms |
23764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
23768 KB |
Output is correct |
2 |
Correct |
14 ms |
23828 KB |
Output is correct |
3 |
Correct |
15 ms |
23892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
105 ms |
24928 KB |
Output is correct |
2 |
Correct |
164 ms |
26276 KB |
Output is correct |
3 |
Correct |
127 ms |
25776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
133 ms |
25496 KB |
Output is correct |
2 |
Correct |
136 ms |
25440 KB |
Output is correct |
3 |
Correct |
174 ms |
26420 KB |
Output is correct |
4 |
Correct |
43 ms |
25284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
121 ms |
25144 KB |
Output is correct |
2 |
Correct |
159 ms |
26656 KB |
Output is correct |
3 |
Correct |
154 ms |
24444 KB |
Output is correct |
4 |
Correct |
127 ms |
26132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
135 ms |
24716 KB |
Output is correct |
2 |
Correct |
147 ms |
25624 KB |
Output is correct |
3 |
Correct |
96 ms |
24748 KB |
Output is correct |
4 |
Correct |
158 ms |
26892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1018 ms |
36340 KB |
Output is correct |
2 |
Incorrect |
615 ms |
28752 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
950 ms |
35660 KB |
Output is correct |
2 |
Incorrect |
730 ms |
28740 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |