Submission #644032

# Submission time Handle Problem Language Result Execution time Memory
644032 2022-09-23T14:49:12 Z ttamx Meteors (POI11_met) C++14
24 / 100
6000 ms 10392 KB
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef tuple<int,int,int> t3;

const int N=3e5+5;

struct fenwick{
    ll tree[N]={};
    void init(){
        for(int i=0;i<N;++i)tree[i]=0;
    }
    void add(int i,ll v){
        while(i<N){
            tree[i]+=v;
            i+=i&-i;
        }
    }
    ll read(int i){
        ll sum=0;
        while(i>0){
            sum+=tree[i];
            i-=i&-i;
        }
        return sum;
    }
}f;

int n,m,k;
int o[N],l[N],r[N],ans[N];
ll p[N];
bool can[N];
vector<t3> v;

int main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	cin >> n >> m;
	for(int i=1;i<=m;++i)cin >> o[i];
	for(int i=1;i<=n;++i)cin >> p[i];
    cin >> k;
    v.emplace_back(0,0,0);
    for(int i=1;i<=k;++i){
        int a,b,c;
        cin >> a >> b >> c;
        v.emplace_back(a,b,c);
    }
    for(int i=1;i<=n;++i)l[i]=0,r[i]=k+1;
    int idx=1;
    while(idx<=n){
        int mid=(l[idx]+r[idx])/2;
        f.init();
        for(int i=1;i<=mid;++i){
            auto [a,b,c]=v[i];
            f.add(a,c);
            f.add(b+1,-c);
            if(b<a){
                f.add(1,c);
                f.add(m+1,-c);
            }
        }
        int sum[N]={};
        for(int i=1;i<=m;++i){
            sum[o[i]]+=f.read(i);
        }
        for(int i=1;i<=n;++i){
            if(l[i]+1>=r[i])continue;
            if((l[i]+r[i])/2!=mid)continue;
            if(sum[i]>=p[i])r[i]=mid,can[i]=true;
            else l[i]=mid;
        }
        if(l[idx]+1>=r[idx])ans[idx]=r[idx],++idx;
    }
    for(int i=1;i<=n;++i){
        if(can[i])cout << ans[i] << '\n';
        else cout << "NIE" << '\n';
    }
	return 0;
}

Compilation message

met.cpp: In function 'int main()':
met.cpp:55:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   55 |             auto [a,b,c]=v[i];
      |                  ^
# Verdict Execution time Memory Grader output
1 Correct 49 ms 3796 KB Output is correct
2 Correct 106 ms 3920 KB Output is correct
3 Correct 90 ms 3916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 3796 KB Output is correct
2 Correct 34 ms 3924 KB Output is correct
3 Correct 213 ms 3920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 6054 ms 4872 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 6055 ms 4940 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 6071 ms 4984 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 6029 ms 4792 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 6051 ms 10392 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 6041 ms 10116 KB Time limit exceeded
2 Halted 0 ms 0 KB -