답안 #975009

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
975009 2024-05-04T09:39:12 Z Ninedesu Meteors (POI11_met) C++14
74 / 100
909 ms 28512 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++){
            ll 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 3 ms 14684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 14856 KB Output is correct
2 Correct 4 ms 14684 KB Output is correct
3 Correct 4 ms 14900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 18008 KB Output is correct
2 Correct 106 ms 18760 KB Output is correct
3 Correct 88 ms 18576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 18432 KB Output is correct
2 Correct 84 ms 18512 KB Output is correct
3 Correct 116 ms 18896 KB Output is correct
4 Correct 42 ms 18264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 18292 KB Output is correct
2 Correct 99 ms 18912 KB Output is correct
3 Correct 20 ms 15196 KB Output is correct
4 Correct 98 ms 18672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 18088 KB Output is correct
2 Correct 91 ms 18528 KB Output is correct
3 Correct 57 ms 18008 KB Output is correct
4 Correct 122 ms 18908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 904 ms 28512 KB Output is correct
2 Incorrect 608 ms 24928 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 909 ms 28216 KB Output is correct
2 Incorrect 556 ms 23948 KB Output isn't correct
3 Halted 0 ms 0 KB -