답안 #975007

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
975007 2024-05-04T09:37:04 Z Ninedesu Meteors (POI11_met) C++14
74 / 100
916 ms 32280 KB
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define piii pair<ll,pii>
using namespace std;

const int N=3e5+1;
int m,n,q;
int arr[N],want[N],l[N],r[N];
piii up[N];
bitset<N>can,vis;
vector<int>own[N];
priority_queue<pii,vector<pii>,greater<pii>>pq;

class fenwick{
    public:

    ll tree[N];

    void reset(){
        for(int i=1; i<=n; i++)tree[i]=0;
    }

    void update(int idx,ll val){
        while(idx<=n){
            tree[idx]+=val;
            idx+=(idx&-idx);
        }
    }

    ll query(int idx){
        ll sum=0;
        while(idx){
            sum+=tree[idx];
            idx-=(idx&-idx);
        }
        return sum;
    }

}fw;

int main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> m >> n;
    for(int i=1; i<=n; i++){
        cin >> arr[i];
        own[arr[i]].push_back(i);
    }
    for(int i=1; i<=m; i++){
        cin >> want[i];
    }
    cin >> q;
    for(int i=1; i<=m; i++){
        l[i]=1;
        r[i]=q;
    }
    for(int i=1; i<=q; i++){
        cin >> up[i].second.first >> up[i].second.second >> up[i].first;
    }
    bool chk=true;
    while(chk){
        chk=false;
        int mxmid=0;
        for(int i=1; i<=m; i++){
            if(vis[i])continue;
            chk=true;
            int mid=(l[i]+r[i])>>1;
            mxmid=max(mxmid,mid);
            pq.push({mid,i});
        }
        for(int i=1; i<=mxmid; i++){
            int z=up[i].first;
            int x=up[i].second.first;
            int y=up[i].second.second;
            if(x<=y){
                fw.update(x,z);
                if(y<n)fw.update(y+1,-z);
            }
            else{
                fw.update(x,z);
                fw.update(1,z);
                fw.update(y+1,-z);
            }
            while(!pq.empty()){
                int mid=pq.top().first;
                int idx=pq.top().second;
                if(mid!=i)break;
                pq.pop();
                ll sum=0;
                for(int j:own[idx]){
                    sum+=fw.query(j);
                }
                if(sum>=want[idx])can[idx]=true;
                if(l[idx]==r[idx])vis[idx]=true;
                if(sum<want[idx])l[idx]=mid+1;
                else r[idx]=mid;
            }
        }
        fw.reset();
    }
    for(int i=1; i<=m; i++){
        if(can[i])cout << l[i] << '\n';
        else cout << "NIE\n";
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14684 KB Output is correct
2 Correct 4 ms 14684 KB Output is correct
3 Correct 4 ms 14840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14684 KB Output is correct
2 Correct 4 ms 14684 KB Output is correct
3 Correct 5 ms 14900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 18268 KB Output is correct
2 Correct 106 ms 19152 KB Output is correct
3 Correct 89 ms 18848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 18756 KB Output is correct
2 Correct 83 ms 18776 KB Output is correct
3 Correct 118 ms 19328 KB Output is correct
4 Correct 39 ms 18264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 18264 KB Output is correct
2 Correct 96 ms 19340 KB Output is correct
3 Correct 20 ms 15192 KB Output is correct
4 Correct 95 ms 19036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 18268 KB Output is correct
2 Correct 88 ms 19108 KB Output is correct
3 Correct 58 ms 18268 KB Output is correct
4 Correct 124 ms 19396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 916 ms 32280 KB Output is correct
2 Incorrect 610 ms 28452 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 868 ms 31836 KB Output is correct
2 Incorrect 516 ms 27100 KB Output isn't correct
3 Halted 0 ms 0 KB -