Submission #477534

# Submission time Handle Problem Language Result Execution time Memory
477534 2021-10-02T13:20:20 Z mat_v Meteors (POI11_met) C++14
0 / 100
1028 ms 44044 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];
int 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[300005];
void upd(int x, int 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 + 300001, 0);
        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){
            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]){
                    ans[c] = i;
                    r[c] = i-1;
                }
                else l[c] = i+1;
            }
        }
    }
    ff(i,1,m)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:60:9: note: in expansion of macro 'ff'
   60 |         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:61:9: note: in expansion of macro 'ff'
   61 |         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:68:9: note: in expansion of macro 'ff'
   68 |         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:82:5: note: in expansion of macro 'ff'
   82 |     ff(i,1,m)cout << ans[i] << "\n";
      |     ^~
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 16772 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 16848 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 77 ms 19404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 85 ms 20152 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 90 ms 19784 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 83 ms 19040 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1028 ms 44044 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 853 ms 42432 KB Output isn't correct
2 Halted 0 ms 0 KB -