#include <algorithm>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <cmath>
#include <queue>
#include <map>
#include <set>
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ent "\n"
const int maxn = 3e5 + 100;
const ll INF = (ll)2e18;
const int inf = (ll)2e9;
const int maxl = 26;
const int MOD = 1e9 + 7;
int n, m, q;
vector<int> g[maxn];
int a[maxn];
int ans[maxn];
ll t[maxn];
int l[maxn];
int r[maxn];
int x[maxn];
vector<int> cl;
void upd(int i, int x){
for(; i <= m; i |= (i + 1)) t[i] += x, cl.push_back(i);
}
void upd(int l, int r, int x){
if(l <= r){
upd(l, x); upd(r + 1, -x);
} else{
upd(1, x);
upd(r + 1, -x);
upd(l, x);
}
}
ll get(int i){
ll res = 0;
for(; i > 0; i = (i & (i + 1)) - 1) res += t[i];
return res;
}
void f(int tl, int tr, vector<int> &v){
if(tl > tr) return;
int mid = (tl + tr) >> 1;
vector<int> L, R;
for(int i = tl; i <= mid; i++){
upd(l[i], r[i], x[i]);
}
for(int x: v){
ll sum = 0;
for(int i: g[x]){
sum = min((ll)1e18, 1ll * get(i) + sum);
}
if(a[x] > sum) a[x] -= sum, R.push_back(x);
else ans[x] = mid, L.push_back(x);
}
for(int x: cl) t[x] = 0;
cl.clear();
f(tl, mid - 1, L);
f(mid + 1, tr, R);
}
void test(){
cin >> n >> m;
for(int i = 1; i <= m; i++){
int x; cin >> x;
g[x].push_back(i);
}
vector<int> v;
for(int i = 1; i <= n; i++){
cin >> a[i]; v.push_back(i);
ans[i] = -1;
}
cin >> q;
for(int i = 1; i <= q; i++){
cin >> l[i] >> r[i] >> x[i];
}
f(1, q, v);
for(int i = 1; i <= n; i++){
if(ans[i] == -1) cout << "NIE\n";
else cout << ans[i] << ent;
}
}
int main(){
// freopen("cows.in", "r", stdin);
// freopen("cows.out", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int t; t = 1;
while(t--) test();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7508 KB |
Output is correct |
2 |
Correct |
4 ms |
7508 KB |
Output is correct |
3 |
Correct |
4 ms |
7508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7508 KB |
Output is correct |
2 |
Correct |
4 ms |
7508 KB |
Output is correct |
3 |
Correct |
4 ms |
7508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
10828 KB |
Output is correct |
2 |
Correct |
92 ms |
13820 KB |
Output is correct |
3 |
Correct |
74 ms |
11208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
13112 KB |
Output is correct |
2 |
Correct |
79 ms |
13116 KB |
Output is correct |
3 |
Correct |
95 ms |
13608 KB |
Output is correct |
4 |
Correct |
22 ms |
9240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
12872 KB |
Output is correct |
2 |
Correct |
69 ms |
13528 KB |
Output is correct |
3 |
Correct |
34 ms |
10192 KB |
Output is correct |
4 |
Correct |
73 ms |
11292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
12820 KB |
Output is correct |
2 |
Correct |
91 ms |
13124 KB |
Output is correct |
3 |
Correct |
64 ms |
10916 KB |
Output is correct |
4 |
Correct |
91 ms |
13636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
756 ms |
51040 KB |
Output is correct |
2 |
Correct |
485 ms |
46284 KB |
Output is correct |
3 |
Correct |
174 ms |
21040 KB |
Output is correct |
4 |
Correct |
928 ms |
62768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
749 ms |
50604 KB |
Output is correct |
2 |
Correct |
467 ms |
46140 KB |
Output is correct |
3 |
Correct |
146 ms |
21456 KB |
Output is correct |
4 |
Correct |
1006 ms |
64176 KB |
Output is correct |