#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define sz(x) (int)x.size()
#define F first
#define S second
#define ll long long
const int dx[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dy[] = {1, 0, -1, 0, -1, 1, -1, 1};
const int maxn = 3e5+7;
const ll inf = 1e18;
const ll mod = 1e9+7;
using namespace std;
int n, m, k;
int s[maxn], p[maxn];
int L[maxn], R[maxn], x[maxn];
ll t[4 * maxn], ps[4 * maxn];
vector <int> cur[maxn];
vector <int> have[maxn];
int res[maxn];
struct node{
int sl, sr;
} seg[maxn];
void push(int tl, int tr, int v){
if(tl != tr){
ps[v * 2] += ps[v];
ps[v * 2 + 1] += ps[v];
}
t[v] += ps[v];
ps[v] = 0;
}
void build(int tl = 1, int tr = m, int v = 1){
t[v] = ps[v] = 0;
if(tl == tr) return;
int md = (tl + tr) / 2;
build(tl, md, v * 2);
build(md + 1, tr, v * 2 + 1);
}
void update(int l, int r, int val, int tl = 1, int tr = m, int v = 1){
push(tl, tr, v);
if(l > tr || tl > r) return;
else if(l <= tl && tr <= r){
ps[v] += val;
push(tl, tr, v);
}else{
int md = (tl + tr) / 2;
update(l, r, val, tl, md, v * 2);
update(l, r, val, md + 1, tr, v * 2 + 1);
}
}
ll get(int pos, int tl = 1, int tr = m, int v = 1){
push(tl, tr, v);
if(tl == tr){
return t[v];
}else{
int md = (tl + tr) / 2;
if(pos <= md) return get(pos, tl, md, v * 2);
else return get(pos, md + 1, tr, v * 2 + 1);
}
}
void solve(){
cin >> n >> m;
for(int i = 1; i <= m; i++){
cin >> s[i];
cur[s[i]].pb(i);
}
for(int i = 1; i <= n; i++){
cin >> p[i];
}
cin >> k;
for(int i = 1; i <= k; i++){
cin >> L[i] >> R[i] >> x[i];
}
for(int i = 1; i <= n; i++){
seg[i].sl = 1; seg[i].sr = k;
}
for(int rep = 1; rep <= 20; rep++){
build();
for(int i = 1; i <= n; i++){
if(seg[i].sl <= seg[i].sr){
int md = (seg[i].sl + seg[i].sr) / 2;
have[md].pb(i);
}
}
for(int i = 1; i <= k; i++){
if(L[i] <= R[i]){
update(L[i], R[i], x[i]);
}else{
update(L[i], m, x[i]);
update(1, R[i], x[i]);
}
for(auto x : have[i]){
ll ans = 0;
for(auto pos : cur[x]){
ans += get(pos);
if(ans >= p[x]) break;
}
if(ans >= p[x]){
res[x] = i;
seg[x].sr = i - 1;
}else{
seg[x].sl = i + 1;
}
}
have[i].clear();
}
}
for(int i = 1; i <= n; i++){
if(res[i] == 0){
cout << "NIE\n";
continue;
}
cout << res[i] << '\n';
}
}
signed main(){
speed
int test = 1;
// cin >> test;
while(test--){
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
24920 KB |
Output is correct |
2 |
Correct |
11 ms |
24924 KB |
Output is correct |
3 |
Correct |
10 ms |
24924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
24920 KB |
Output is correct |
2 |
Correct |
10 ms |
24924 KB |
Output is correct |
3 |
Correct |
11 ms |
24920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
405 ms |
25680 KB |
Output is correct |
2 |
Correct |
500 ms |
29920 KB |
Output is correct |
3 |
Correct |
473 ms |
27344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
455 ms |
26928 KB |
Output is correct |
2 |
Correct |
466 ms |
27116 KB |
Output is correct |
3 |
Correct |
471 ms |
29776 KB |
Output is correct |
4 |
Correct |
92 ms |
26680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
217 ms |
26372 KB |
Output is correct |
2 |
Correct |
366 ms |
30460 KB |
Output is correct |
3 |
Correct |
222 ms |
25364 KB |
Output is correct |
4 |
Correct |
464 ms |
27724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
440 ms |
25436 KB |
Output is correct |
2 |
Correct |
410 ms |
27028 KB |
Output is correct |
3 |
Correct |
441 ms |
25784 KB |
Output is correct |
4 |
Correct |
494 ms |
31124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4277 ms |
55076 KB |
Output is correct |
2 |
Correct |
2197 ms |
41812 KB |
Output is correct |
3 |
Correct |
1091 ms |
27784 KB |
Output is correct |
4 |
Runtime error |
4034 ms |
65536 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4106 ms |
53784 KB |
Output is correct |
2 |
Correct |
1193 ms |
41800 KB |
Output is correct |
3 |
Correct |
882 ms |
28752 KB |
Output is correct |
4 |
Runtime error |
3353 ms |
65536 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |