Submission #920451

# Submission time Handle Problem Language Result Execution time Memory
920451 2024-02-02T14:49:23 Z NotLinux Meteors (POI11_met) C++17
61 / 100
814 ms 51044 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
struct FENWICK{
    vector < int > fen;
    int sz;
    FENWICK(int x){
        sz = x+3;
        fen.assign(sz,0);
    }
    inline void update(int p , int x)  {
        while(p <= sz){
            fen[p] += x;
            p += p & (-p);
            //cout << "update:" << p << " " << sz << endl;
        }
    }
    inline int query(int x){
        int ret = 0;
        while(x != 0){
            ret += fen[x];
            x -= x & (-x);
            //cout <<"query:"<< x << endl;
        }
        return ret;
    }
    inline void rangeupdate(int l , int r,int x){
        update(l,x);
        if(r != sz)update(r+1,-x);
    }
};

void solve(){
    int n,m;cin >> n >> m;
    vector < int > devlet[n+1];
    for(int i = 1;i<=m;i++){
        int x;cin >> x;
        devlet[x].push_back(i);
    }
    int need[n+1];
    for(int i = 1;i<=n;i++){
        cin >> need[i];
    }
    int q;cin >> q;
    vector < array < int , 3 > > query(q+1);
    for(int i = 1;i<=q;i++){
        cin >> query[i][0] >> query[i][1] >> query[i][2];
    }

    vector < array < int , 3 > > paralel[q+2],nparalel[q+2];
    for(int i = 1;i<=n;i++){
        paralel[(1+q+1)/2].push_back({i,1,q+1});
    }
    for(int i = 0;i<=19;i++){
        FENWICK fen(m+10);
        for(int j = 1;j<=q;j++){
            if(query[j][0] <= query[j][1]){
                fen.rangeupdate(query[j][0],query[j][1],query[j][2]);
            }
            else{
                fen.rangeupdate(1,query[j][1],query[j][2]);
                fen.rangeupdate(query[j][0],m+1,query[j][2]);
            }
            for(auto itr : paralel[j]){
                if(itr[1] == itr[2]){
                    nparalel[j].push_back(itr);
                    continue;
                }
                int cur = 0;
                for(auto itr1 : devlet[itr[0]]){
                    cur += fen.query(itr1);
                }
                if(cur >= need[itr[0]]){//r = mid;
                    int mid = (itr[1] + j)/2;
                    nparalel[mid].push_back({itr[0],itr[1],j});
                }
                else {//l = mid
                    int mid = (j+1 + itr[2])/2;
                    nparalel[mid].push_back({itr[0],j+1,itr[2]});
                }
            }
        }
        for(int j = 1;j<=q;j++){
            paralel[j].swap(nparalel[j]);
            nparalel[j].clear();
        }
    }
    int ans[n+1];
    memset(ans , -1 , sizeof(ans));
    for(int j = 1;j<=q;j++){
        for(auto itr : paralel[j]){
            ans[itr[0]] = j;
        }
    }
    for(int i = 1;i<=n;i++){
        if(ans[i] == -1)cout << "NIE" << '\n';
        else cout << ans[i] << '\n';
    }
}
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int testcase = 1;//cin >> testcase;
    while(testcase--)solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 2 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 5116 KB Output is correct
2 Correct 90 ms 9832 KB Output is correct
3 Correct 81 ms 8268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 82 ms 6992 KB Output is correct
2 Correct 91 ms 7500 KB Output is correct
3 Correct 92 ms 10776 KB Output is correct
4 Correct 24 ms 4932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 5516 KB Output is correct
2 Correct 70 ms 10824 KB Output is correct
3 Correct 45 ms 3416 KB Output is correct
4 Correct 81 ms 9272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 75 ms 3900 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 814 ms 51044 KB Output is correct
2 Incorrect 425 ms 20396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 797 ms 48188 KB Output is correct
2 Incorrect 454 ms 20416 KB Output isn't correct
3 Halted 0 ms 0 KB -