Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define F first
- #define S second
- #define all(x) x.begin(),x.end()
- #define endl '\n'
- using namespace std;
- using ll = long long;
- using pii = pair<int, int>;
- const int INF = 0x3f3f3f3f;
- const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
- const int MOD = 1000000007;
- const int dx[] = { 0, 0, -1, 1, 1, -1, 1, -1};
- const int dy[] = {-1, 1, 0, 0, 1, -1, -1, 1};
- const int MAXN = 300010;
- typedef long long t_bit;
- t_bit bit[MAXN];
- //1-indexed
- t_bit get(int i){
- t_bit s = 0;
- for (; i > 0; i -= (i & -i))
- s += bit[i];
- return s;
- }
- //1-indexed
- void add(int i, t_bit value){
- assert(i > 0);
- for (; i < MAXN; i += (i & -i))
- bit[i] += value;
- }
- void add(int l, int r, t_bit val){
- if(l <= r){
- add(l, val);
- add(r+1, -val);
- }else{
- add(l, val);
- add(1, val);
- add(r+1, -val);
- }
- }
- typedef tuple<int, int, int> tp;
- vector<int> pos[MAXN];
- int p[MAXN], ans[MAXN];
- tp q[MAXN];
- void solve(int i, int j, vector<int> &v){
- if(i == j){
- for(int x: v)
- ans[x] = i;
- return;
- }
- int mid = (i+j)/2;
- for(int k=i; k<=mid; k++){
- auto [l, r, a] = q[k];
- add(l, r, a);
- }
- vector<int> left, right;
- for(int x: v){
- ll sum = 0;
- for(int y: pos[x]){
- sum += get(y);
- if(sum >= p[x])
- break;
- }
- if(sum >= p[x])
- left.push_back(x);
- else
- right.push_back(x);
- }
- v.clear();
- solve(mid+1, j, right);
- for(int k=mid; k>=i; k--){
- auto [l, r, a] = q[k];
- add(l, r, -a);
- }
- solve(i, mid, left);
- }
- int main() {
- ios_base::sync_with_stdio(false); cin.tie(NULL);
- int n, m;
- cin >> n >> m;
- for(int i=1; i<=m; i++){
- int x;
- cin >> x;
- pos[x].push_back(i);
- }
- for(int i=1; i<=n; i++){
- cin >> p[i];
- }
- int k;
- cin >> k;
- for(int i=1; i<=k; i++){
- int l, r, a;
- cin >> l >> r >> a;
- q[i] = tp(l, r, a);
- }
- q[k+1] = tp(1, m, 1e9);
- vector<int> v(n);
- iota(all(v), 1);
- solve(1, k+1, v);
- for(int i=1; i<=n; i++){
- if(ans[i] > k)
- cout << "NIE" << endl;
- else
- cout << ans[i] << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement