Submission #477746

# Submission time Handle Problem Language Result Execution time Memory
477746 2021-10-03T11:16:35 Z mat_v Meteors (POI11_met) C++14
74 / 100
1095 ms 38212 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]){
                    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:88:5: note: in expansion of macro 'ff'
   88 |     ff(i,1,m){
      |     ^~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 17540 KB Output is correct
2 Correct 12 ms 17612 KB Output is correct
3 Correct 11 ms 17568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 17640 KB Output is correct
2 Correct 13 ms 17628 KB Output is correct
3 Correct 12 ms 17636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 19372 KB Output is correct
2 Correct 125 ms 21640 KB Output is correct
3 Correct 125 ms 21132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 110 ms 20424 KB Output is correct
2 Correct 116 ms 20548 KB Output is correct
3 Correct 137 ms 21684 KB Output is correct
4 Correct 51 ms 19804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 19784 KB Output is correct
2 Correct 105 ms 22200 KB Output is correct
3 Correct 54 ms 18420 KB Output is correct
4 Correct 110 ms 21572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 18904 KB Output is correct
2 Correct 113 ms 20476 KB Output is correct
3 Correct 99 ms 19140 KB Output is correct
4 Correct 142 ms 22892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1046 ms 38212 KB Output is correct
2 Incorrect 765 ms 24752 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1095 ms 36600 KB Output is correct
2 Incorrect 714 ms 24740 KB Output isn't correct
3 Halted 0 ms 0 KB -