답안 #461241

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
461241 2021-08-09T15:25:02 Z vanic Nuclearia (CEOI15_nuclearia) C++14
15 / 100
1000 ms 266704 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);
	ll a, b, c, d;
	int kol;
	int l, r;
	pair < ll, ll > val;
	for(int i=0; i<n; i++){
		scanf("%lld%lld%lld%lld", &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("%lld%lld%lld%lld", &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("%lld%lld%lld%lld", &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("%lld%lld%lld%lld", &a, &b, &c, &d);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 134364 KB Output is correct
2 Correct 206 ms 134028 KB Output is correct
3 Correct 179 ms 133644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 134576 KB Output is correct
2 Correct 196 ms 134004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 184 ms 266632 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 187 ms 266600 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 479 ms 172912 KB Output is correct
2 Correct 211 ms 136560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 403 ms 149636 KB Output is correct
2 Correct 198 ms 135976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 213 ms 266676 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 190 ms 266696 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1101 ms 173100 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1084 ms 172068 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Runtime error 189 ms 266688 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 189 ms 266692 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 187 ms 266704 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 203 ms 266696 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -