Submission #748285

# Submission time Handle Problem Language Result Execution time Memory
748285 2023-05-26T03:23:26 Z jamezzz Meteors (POI11_met) C++17
24 / 100
1535 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;

#define sf scanf
#define pf printf
#define pb push_back
#define INF 1023456789
typedef long long ll;
typedef vector<int> vi;

struct node{
	int s,e,m;ll v,lz;
	node *l,*r;
	node(int _s,int _e){
		s=_s,e=_e,m=(s+e)>>1,v=0;
		if(s!=e)l=new node(s,m),r=new node(m+1,e);
	}
	void up(int x,int y,int nv){
		if(s==x&&e==y){v+=nv;return;}
		if(y<=m)l->up(x,y,nv);
		else if(x>m)r->up(x,y,nv);
		else l->up(x,m,nv),r->up(m+1,y,nv);
	}
	ll qry(int x){
		if(s==x&&e==x)return v;
		if(x<=m)return v+l->qry(x);
		else return v+r->qry(x);
	}
}*rt;

#define maxn 300005

int n,m,p[maxn],k,l[maxn],r[maxn],a[maxn],ans[maxn];
vi s[maxn];

int main(){
	sf("%d%d",&n,&m);
	for(int i=1;i<=m;++i){
		int o;sf("%d",&o);
		s[o].pb(i);
	}
	vi v;
	for(int i=1;i<=n;++i){
		sf("%d",&p[i]);
		v.pb(i);
		ans[i]=-1;
	}
	sf("%d",&k);
	for(int i=1;i<=k;++i)sf("%d%d%d",&l[i],&r[i],&a[i]);
	queue<tuple<int,int,vi>> q;
	q.push({1,k,v});
	int pv=INF;
	while(!q.empty()){
		auto[lo,hi,v]=q.front();
		q.pop();
		if(lo>hi||v.empty())continue;
		int mid=(lo+hi)>>1;
		if(mid<pv)rt=new node(1,m),pv=0;
		while(pv<mid){
			++pv;
			if(l[pv]<=r[pv])rt->up(l[pv],r[pv],a[pv]);
			else rt->up(l[pv],m,a[pv]),rt->up(1,r[pv],a[pv]);
		}
		vi lv,rv;
		for(int x:v){
			ll tot=0;
			for(int i:s[x]){
				tot+=rt->qry(i);
				if(tot>=p[x])break;
			}
			if(tot>=p[x])lv.pb(x),ans[x]=mid;
			else rv.pb(x);
		}
		q.push({lo,mid-1,lv});
		q.push({mid+1,hi,rv});
	}
	for(int i=1;i<=n;++i){
		if(ans[i]==-1)pf("NIE\n");
		else pf("%d\n",ans[i]);
	}
}

Compilation message

met.cpp: In function 'int main()':
met.cpp:37:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |  sf("%d%d",&n,&m);
      |    ^
met.cpp:39:11: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |   int o;sf("%d",&o);
      |           ^
met.cpp:44:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |   sf("%d",&p[i]);
      |     ^
met.cpp:48:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |  sf("%d",&k);
      |    ^
met.cpp:49:25: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |  for(int i=1;i<=k;++i)sf("%d%d%d",&l[i],&r[i],&a[i]);
      |                         ^
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8660 KB Output is correct
2 Correct 8 ms 8660 KB Output is correct
3 Correct 9 ms 8660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8660 KB Output is correct
2 Correct 8 ms 8608 KB Output is correct
3 Correct 8 ms 8660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 266 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 281 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 132 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 137 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1535 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1184 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -