Submission #1049299

# Submission time Handle Problem Language Result Execution time Memory
1049299 2024-08-08T16:08:07 Z Newtonabc Meteors (POI11_met) C++14
74 / 100
970 ms 43144 KB
#include<bits/stdc++.h>
using namespace std;
const int N=3e5+10;
const int M=3e5+5;
int o[N],al[N],ar[N],mid[N],l[N],r[N];
long long p[N],a[N],fw[N],s[N];
vector<int> ask[N];
vector<int> own[N];

void update(int idx,long long val){
	if(idx==0) return;
	while(idx<=M){
		fw[idx]+=val;
		idx+=idx & -idx;
	}
}

long long read(int idx){
	long long sum=0;
	while(idx>0){
		sum+=fw[idx];
		idx-=idx & -idx;
	}
	return sum;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,m,k;
	cin>>n >>m;
	for(int i=1;i<=m;i++) cin>>o[i],own[o[i]].push_back(i);
	for(int i=1;i<=n;i++) cin>>p[i];
	cin>>k;
	for(int i=1;i<=k;i++) cin>>al[i] >>ar[i] >>a[i];
	for(int i=1;i<=n;i++) l[i]=1,r[i]=k;
	while(true){
		bool up=false;
		for(int i=1;i<=k;i++) ask[i].clear();
		for(int i=1;i<=n;i++) mid[i]=(l[i]+r[i])/2,ask[mid[i]].push_back(i);
		for(int i=0;i<=M;i++) fw[i]=0;
		for(int i=1;i<=k;i++){
			if(al[i]<=ar[i]) update(al[i],a[i]),update(ar[i]+1,-1*a[i]);
			else update(al[i],a[i]),update(m+1,-1*a[i]),update(1,a[i]),update(ar[i]+1,-1*a[i]);
			for(int j=0;j<ask[i].size();j++){
				int u=ask[i][j];
				long long sum=0;
				for(int x=0;x<own[u].size();x++){
					sum+=read(own[u][x]);
					if(sum>1e9) sum=1e9+1;
				}
				if(sum>=p[u]){
					if(r[u]!=mid[u]) up=true;
					r[u]=mid[u];
				}
				else{
					if(l[u]!=mid[u]+1) up=true;
					l[u]=mid[u]+1;
				}
			}
		}
		if(!up) break;
	}
	for(int i=0;i<=M;i++) fw[i]=0;
	for(int i=1;i<=k;i++){
		if(al[i]<=ar[i]) update(al[i],a[i]),update(ar[i]+1,-1*a[i]);
		else update(al[i],a[i]),update(m+1,-1*a[i]),update(1,a[i]),update(ar[i]+1,-1*a[i]);
	}
	for(int i=1;i<=n;i++){
		long long sum=0;
		for(int j=0;j<own[i].size();j++){
			sum+=read(own[i][j]);
		}
		s[i]=sum;
	}
	for(int i=1;i<=n;i++){
		if(s[i]<p[i]) cout<<"NIE";
		else cout<<l[i];
		cout<<"\n";
	}
}

Compilation message

met.cpp: In function 'int main()':
met.cpp:45:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |    for(int j=0;j<ask[i].size();j++){
      |                ~^~~~~~~~~~~~~~
met.cpp:48:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for(int x=0;x<own[u].size();x++){
      |                 ~^~~~~~~~~~~~~~
met.cpp:71:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |   for(int j=0;j<own[i].size();j++){
      |               ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 29276 KB Output is correct
2 Correct 5 ms 29276 KB Output is correct
3 Correct 5 ms 29276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 29272 KB Output is correct
2 Correct 5 ms 29276 KB Output is correct
3 Correct 5 ms 29396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 30264 KB Output is correct
2 Correct 181 ms 32088 KB Output is correct
3 Correct 119 ms 31824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 155 ms 31140 KB Output is correct
2 Correct 141 ms 31272 KB Output is correct
3 Correct 181 ms 32084 KB Output is correct
4 Correct 21 ms 31320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 112 ms 30600 KB Output is correct
2 Correct 174 ms 32592 KB Output is correct
3 Correct 150 ms 29272 KB Output is correct
4 Correct 105 ms 32084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 165 ms 29880 KB Output is correct
2 Correct 180 ms 31056 KB Output is correct
3 Correct 100 ms 30156 KB Output is correct
4 Correct 153 ms 33316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 970 ms 43144 KB Output is correct
2 Incorrect 710 ms 32352 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 961 ms 42192 KB Output is correct
2 Incorrect 731 ms 32216 KB Output isn't correct
3 Halted 0 ms 0 KB -