Submission #461243

# Submission time Handle Problem Language Result Execution time Memory
461243 2021-08-09T15:27:12 Z vanic Nuclearia (CEOI15_nuclearia) C++14
15 / 100
1000 ms 266728 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, ll &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){
		ll 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){
		ll 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 < ll, ll > 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-l*d, d};
			l=0;
		}
//		cout << "upd " << val.first << ' ' << val.second << endl;
		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);
		}
	}
/*	for(int i=0; i<w; i++){
		cout << T.query(0, pot-1, 1, i, i) << ' ';
	}
	cout << endl;*/
	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((long 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:122:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  122 |  scanf("%d", &q);
      |  ~~~~~^~~~~~~~~~
nuclearia.cpp:124:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  124 |   scanf("%d%d%d%d", &a, &b, &c, &d);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 58 ms 134320 KB Output is correct
2 Correct 201 ms 134148 KB Output is correct
3 Correct 176 ms 133680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 134596 KB Output is correct
2 Correct 202 ms 134132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 180 ms 266728 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 184 ms 266692 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 478 ms 172996 KB Output is correct
2 Correct 224 ms 134296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 395 ms 149736 KB Output is correct
2 Correct 203 ms 134004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 183 ms 266708 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 187 ms 266692 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1083 ms 172536 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1096 ms 172848 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Runtime error 181 ms 266708 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 185 ms 266612 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 187 ms 266652 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 181 ms 266620 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -