Submission #477748

# Submission time Handle Problem Language Result Execution time Memory
477748 2021-10-03T11:24:09 Z mat_v Meteors (POI11_met) C++14
100 / 100
2077 ms 64440 KB
#include <bits/stdc++.h>
#define pb push_back
#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
using namespace std;
typedef long long ll;

int n,m,q;
int niz[300005];
vector<int> drz[300005];
ll targ[300005];
int le[300005];
int ri[300005];
ll val[300005];

vector<int> buc[300005];
int l[300005];
int r[300005];
int bucs[300005];
int ans[300005];


ll bit[400005];
void upd(int x, ll val){
    while(x <= n){
        bit[x] += val;
        x += (x&-x);
    }
}
ll kveri(int x){
    ll res = 0;
    while(x > 0){
        res += bit[x];
        x -= (x&-x);
    }
    return res;
}

int main()
{
    ios_base::sync_with_stdio(false);

    cin >> m >> n;
    ff(i,1,n){
        cin >> niz[i];
        drz[niz[i]].pb(i);
    }
    ff(i,1,m)cin >> targ[i];
    cin >> q;
    ff(i,1,q)cin >> le[i] >> ri[i] >> val[i];
    ff(i,1,m){
        l[i] = 1;
        r[i] = q;
        bucs[i] = (1+q)/2;
        ans[i] = -1;
    }
    while(1){
        bool ch = 0;
        fill(bit, bit + 400000, 0LL);
        ff(i,1,q)buc[i].clear();
        ff(i,1,m){
            if(l[i] <= r[i]){
                ch = 1;
                buc[(l[i] + r[i]) / 2].pb(i);
            }
        }
        if(!ch)break;
        ff(i,1,q){
            if(le[i] > ri[i]){
                upd(le[i], val[i]);
                upd(1, val[i]);
                upd(ri[i] + 1, -val[i]);
            }
            else{
                upd(le[i], val[i]);
                upd(ri[i] + 1, -val[i]);
            }
            for(auto c:buc[i]){
                ll sm = 0;
                for(auto tt:drz[c]){
                    sm += kveri(tt);
                    if(sm >= targ[c])break;
                }
                if(sm >= targ[c]){
                    ans[c] = i;
                    r[c] = i-1;
                }
                else l[c] = i+1;
            }
        }
    }
    ff(i,1,m){
        if(ans[i] == -1 || ans[i] > q)cout << "NIE\n";
        else cout << ans[i] << "\n";
    }

    return 0;
}

Compilation message

met.cpp: In function 'int main()':
met.cpp:3:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    3 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
met.cpp:43:5: note: in expansion of macro 'ff'
   43 |     ff(i,1,n){
      |     ^~
met.cpp:3:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    3 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
met.cpp:47:5: note: in expansion of macro 'ff'
   47 |     ff(i,1,m)cin >> targ[i];
      |     ^~
met.cpp:3:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    3 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
met.cpp:49:5: note: in expansion of macro 'ff'
   49 |     ff(i,1,q)cin >> le[i] >> ri[i] >> val[i];
      |     ^~
met.cpp:3:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    3 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
met.cpp:50:5: note: in expansion of macro 'ff'
   50 |     ff(i,1,m){
      |     ^~
met.cpp:3:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    3 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
met.cpp:59:9: note: in expansion of macro 'ff'
   59 |         ff(i,1,q)buc[i].clear();
      |         ^~
met.cpp:3:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    3 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
met.cpp:60:9: note: in expansion of macro 'ff'
   60 |         ff(i,1,m){
      |         ^~
met.cpp:3:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    3 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
met.cpp:67:9: note: in expansion of macro 'ff'
   67 |         ff(i,1,q){
      |         ^~
met.cpp:3:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    3 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
met.cpp:91:5: note: in expansion of macro 'ff'
   91 |     ff(i,1,m){
      |     ^~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 17612 KB Output is correct
2 Correct 12 ms 17612 KB Output is correct
3 Correct 12 ms 17624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 17612 KB Output is correct
2 Correct 12 ms 17556 KB Output is correct
3 Correct 17 ms 17664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 19336 KB Output is correct
2 Correct 133 ms 21564 KB Output is correct
3 Correct 116 ms 21124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 133 ms 20520 KB Output is correct
2 Correct 114 ms 20476 KB Output is correct
3 Correct 132 ms 21648 KB Output is correct
4 Correct 41 ms 19800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 95 ms 19784 KB Output is correct
2 Correct 117 ms 22188 KB Output is correct
3 Correct 59 ms 18380 KB Output is correct
4 Correct 125 ms 21580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 93 ms 18908 KB Output is correct
2 Correct 108 ms 20472 KB Output is correct
3 Correct 87 ms 19296 KB Output is correct
4 Correct 141 ms 22972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1090 ms 38224 KB Output is correct
2 Correct 800 ms 24748 KB Output is correct
3 Correct 269 ms 23076 KB Output is correct
4 Correct 1843 ms 60316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1134 ms 36784 KB Output is correct
2 Correct 698 ms 24744 KB Output is correct
3 Correct 228 ms 22196 KB Output is correct
4 Correct 2077 ms 64440 KB Output is correct