#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int q, n, m;
pii Q[300005];
int A[300005], B[300005], ans[300005], L[300005], R[300005];
vector <int> grr[300005];
int ft[300005];
void upd(int l, int r, int v){
r++;
for(;l<=m;l+=(l & -l))ft[l] += v;
for(;r<=m;r+=(r & -r))ft[r] -= v;
}
int qry(int p){
int res = 0;
for(;p;p-=(p & -p))res += ft[p];
return res;
}
void solve(){
cin >> n >> m;
for(int i=1;i<=m;i++)cin >> B[i], grr[B[i]].push_back(i);
for(int i=1;i<=n;i++)cin >> A[i];
cin >> q;
for(int i=1;i<=q;i++)cin >> Q[i].fi >> Q[i].se.fi >> Q[i].se.se;
for(int i=1;i<=n;i++)ans[i] = q + 5, L[i] = 1, R[i] = q;
for(int i=0;i<25;i++){
vector <pi> ord;
for(int j = 1; j <= n; j++){
if(L[j] > R[j])continue;
int mid = (L[j] + R[j]) >> 1;
ord.push_back({mid, j});
}
sort(ord.begin(), ord.end());
for(int j = 1; j <= m; j++)ft[j] = 0;
int in = 0;
for(int j = 1; j <= q; j++){
if(Q[j].fi <= Q[j].se.fi)upd(Q[j].fi, Q[j].se.fi, Q[j].se.se);
else upd(Q[j].fi, m, Q[j].se.se), upd(1, Q[j].se.fi, Q[j].se.se);
while(in < (int)ord.size() && ord[in].fi == j){
int tmp = 0;
for(auto k : grr[ord[in].se])tmp += qry(k);
if(tmp >= A[ord[in].se])ans[ord[in].se] = j, R[ord[in].se] = j - 1;
else L[ord[in].se] = j + 1;
in++;
}
}
}
for(int i=1;i<=n;i++){
if(ans[i] <= q)cout << ans[i] << '\n';
else cout << "NIE\n";
}
}
main(){
ios::sync_with_stdio(0);cin.tie(0);
int tc = 1;
//cin >> tc;
for(int tc1=1;tc1<=tc;tc1++){
// cout << "Case #" << tc1 << ": ";
solve();
}
}
Compilation message
met.cpp:67:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
67 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
7380 KB |
Output is correct |
2 |
Correct |
6 ms |
7508 KB |
Output is correct |
3 |
Correct |
6 ms |
7380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
7380 KB |
Output is correct |
2 |
Correct |
6 ms |
7380 KB |
Output is correct |
3 |
Correct |
6 ms |
7508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
10308 KB |
Output is correct |
2 |
Correct |
145 ms |
11936 KB |
Output is correct |
3 |
Correct |
112 ms |
10996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
117 ms |
10716 KB |
Output is correct |
2 |
Correct |
116 ms |
10744 KB |
Output is correct |
3 |
Correct |
148 ms |
11996 KB |
Output is correct |
4 |
Correct |
43 ms |
10088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
94 ms |
10432 KB |
Output is correct |
2 |
Correct |
139 ms |
11844 KB |
Output is correct |
3 |
Correct |
62 ms |
8532 KB |
Output is correct |
4 |
Correct |
116 ms |
11448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
101 ms |
9908 KB |
Output is correct |
2 |
Correct |
123 ms |
10928 KB |
Output is correct |
3 |
Correct |
82 ms |
10068 KB |
Output is correct |
4 |
Correct |
153 ms |
12020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1185 ms |
31252 KB |
Output is correct |
2 |
Incorrect |
798 ms |
21712 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1166 ms |
30320 KB |
Output is correct |
2 |
Incorrect |
979 ms |
21700 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |