Submission #477743

# Submission time Handle Problem Language Result Execution time Memory
477743 2021-10-03T11:13:01 Z mat_v Meteors (POI11_met) C++14
74 / 100
1030 ms 38244 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];
    int t = q;
    ff(i,1,t){
    }
    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)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:51:5: note: in expansion of macro 'ff'
   51 |     ff(i,1,t){
      |     ^~
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:53:5: note: in expansion of macro 'ff'
   53 |     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:62:9: note: in expansion of macro 'ff'
   62 |         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:63:9: note: in expansion of macro 'ff'
   63 |         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:70:9: note: in expansion of macro 'ff'
   70 |         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 11 ms 17612 KB Output is correct
2 Correct 12 ms 17672 KB Output is correct
3 Correct 11 ms 17612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 17612 KB Output is correct
2 Correct 11 ms 17612 KB Output is correct
3 Correct 13 ms 17612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 19384 KB Output is correct
2 Correct 123 ms 21580 KB Output is correct
3 Correct 117 ms 21096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 106 ms 20420 KB Output is correct
2 Correct 115 ms 20512 KB Output is correct
3 Correct 125 ms 21732 KB Output is correct
4 Correct 40 ms 19780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 19780 KB Output is correct
2 Correct 108 ms 22248 KB Output is correct
3 Correct 56 ms 18420 KB Output is correct
4 Correct 111 ms 21576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 18884 KB Output is correct
2 Correct 112 ms 20548 KB Output is correct
3 Correct 82 ms 19148 KB Output is correct
4 Correct 131 ms 22972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1030 ms 38244 KB Output is correct
2 Incorrect 778 ms 24784 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1022 ms 36644 KB Output is correct
2 Incorrect 750 ms 24768 KB Output isn't correct
3 Halted 0 ms 0 KB -