Submission #461218

# Submission time Handle Problem Language Result Execution time Memory
461218 2021-08-09T14:22:04 Z vanic Nuclearia (CEOI15_nuclearia) C++14
0 / 100
1000 ms 266784 KB
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cassert>

using namespace std;
typedef long long ll;

const int Log=22, pot=(1<<Log);


struct tournament{
	ll t[pot*2];
	pair < ll, ll > prop[pot*2];
	void propagate(int &x, int &range){
		if(!prop[x].first && !prop[x].second){
			return;
		}
		t[x]+=prop[x].first*range+prop[x].second*(range*(range-1)/2);
		if(x<pot){
			prop[x*2].first+=prop[x].first;
			prop[x*2].second+=prop[x].second;
			prop[x*2+1].first+=prop[x].first+prop[x].second*range/2;
			prop[x*2+1].second+=prop[x].second;
		}
		prop[x].first=0;
		prop[x].second=0;
	}
	void update(int x, ll val){
		for(; x>0; x/=2){
			t[x]+=val;
		}
	}
	void update2(int L, int D, int x, int l, int d, pair < ll, ll > val){
		int range=D-L+1;
		propagate(x, range);
		if(L>=l && D<=d){
			update(x, val.first*range+val.second*(range*(range-1)/2));
			if(x<pot){
				prop[x*2].first+=val.first;
				prop[x*2].second+=val.second;
				prop[x*2+1].first+=val.first+val.second*range/2;
				prop[x*2+1].second+=val.second;
			}
			return;
		}
		if((L+D)/2>=l){
			update2(L, (L+D)/2, x*2, l, min(d, (L+D)/2), val);
			val.first+=val.second*(min((L+D)/2, d)-l+1);
		}
		if((L+D)/2+1<=d){
			update2((L+D)/2+1, D, x*2+1, max(l, (L+D)/2+1), d, val);
		}
	}
	ll query(int L, int D, int x, int l, int d){
		int range=D-L+1;
		propagate(x, range);
		if(L>=l && D<=d){
			return t[x];
		}
		ll lijeva=0, desna=0;
		if((L+D)/2>=l){
			lijeva=query(L, (L+D)/2, x*2, l, d);
		}
		if((L+D)/2+1<=d){
			desna=query((L+D)/2+1, D, x*2+1, l, d);
		}
		return lijeva+desna;
	}
};

tournament T;


int main(){
	int h, w;
	scanf("%d%d", &w, &h);
	bool p=0;
	if(h>w){
		swap(h, w);
	}
	assert(h==1);
	int n, q;
	scanf("%d", &n);
	int a, b, c, d;
	int kol;
	int l, r;
	pair < int, int > val;
	for(int i=0; i<n; i++){
		scanf("%d%d%d%d", &a, &b, &c, &d);
		a--;
		b--;
		if(!p){
			swap(a, b);
		}
		kol=c/d;
		l=b-kol;
		r=b;
		if(l>-1){
			val={c%d, d};
		}
		else{
			val={c%d+d*-l, d};
			l=0;
		}
		T.update2(0, pot-1, 1, l, r, val);
		l=b+1;
		r=b+kol;
		r=min(r, w-1);
		val={c-d, -d};
		if(l<=r){
			T.update2(0, pot-1, 1, l, r, val);
		}
	}
	scanf("%d", &q);
	for(int i=0; i<q; i++){
		scanf("%d%d%d%d", &a, &b, &c, &d);
		a--;
		b--;
		c--;
		d--;
		if(!p){
			swap(a, b);
			swap(c, d);
		}
		printf("%lld\n", (ll)round((double)T.query(0, pot-1, 1, b, d)/(d-b+1)));
//		printf("%lld\n", (ll)T.query(0, pot-1, 1, b, d));
	}
	return 0;
}

Compilation message

nuclearia.cpp: In function 'int main()':
nuclearia.cpp:79:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |  scanf("%d%d", &w, &h);
      |  ~~~~~^~~~~~~~~~~~~~~~
nuclearia.cpp:86:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
nuclearia.cpp:92:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |   scanf("%d%d%d%d", &a, &b, &c, &d);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
nuclearia.cpp:117:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  117 |  scanf("%d", &q);
      |  ~~~~~^~~~~~~~~~
nuclearia.cpp:119:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  119 |   scanf("%d%d%d%d", &a, &b, &c, &d);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 56 ms 134340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 56 ms 134692 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 185 ms 266624 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 183 ms 266596 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 471 ms 176712 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 400 ms 153172 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 188 ms 266764 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 190 ms 266760 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1077 ms 177448 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1097 ms 177932 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Runtime error 188 ms 266752 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 188 ms 266784 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 194 ms 266768 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 190 ms 266772 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -