Submission #814348

# Submission time Handle Problem Language Result Execution time Memory
814348 2023-08-08T06:59:45 Z 이종영(#10372) Posters on the wall (CPSPC17_posters) C++17
90 / 100
687 ms 338444 KB
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
using ll=long long;
using pii=array<int,2>;
using ti4=array<int,4>;
const ll inf=1e18;
const int N=50005;
int r,c,n,q,x[2*N],y[2*N],nx,ny;
ll prv,m;
ti4 a[N];
vector<pii> ev1[2*N],ev2[2*N];
struct node{
	int l=0,r=0;
	ll a=0,sa=0;
	ll b=0,sb=0;
};
vector<node> T;
int roots[2*N];
void upd(int n1,int n2,int l,int r,int s,int e,ll v1,ll v2){
	if(r<s||e<l) assert(0);
	T[n2]=T[n1];
	ll d=r-l+1;
	if(s<=l&&r<=e){
		T[n2].a+=v1;
		T[n2].sa+=v1*d;
		T[n2].b+=v2;
		T[n2].sb+=v2*d;
		return;
	}
	int m=(l+r)>>1;
	if(s<=m){
		T[n2].l=T.size(); T.emplace_back();
		T[T[n2].l]=T[T[n1].l];
		upd(T[n1].l,T[n2].l,l,m,s,e,v1,v2);
	}
	if(m<e){
		T[n2].r=T.size(); T.emplace_back();
		T[T[n2].r]=T[T[n1].r];
		upd(T[n1].r,T[n2].r,m+1,r,s,e,v1,v2);
	}
	T[n2].sa=T[T[n2].l].sa+T[T[n2].r].sa+T[n2].a*d;
	T[n2].sb=T[T[n2].l].sb+T[T[n2].r].sb+T[n2].b*d;
}
ll qry(int nd,int l,int r,int s,int e,ll x){
	if(!nd||r<s||e<l) return 0;
	if(s<=l&&r<=e) return T[nd].sa*x+T[nd].sb;
	int m=(l+r)>>1;
	ll val=qry(T[nd].l,l,m,s,e,x)+qry(T[nd].r,m+1,r,s,e,x);
	ll d=min(e,r)-max(l,s)+1;
	return val+T[nd].a*d*x+T[nd].b*d;
}
ll solve(int x1,int y1,int y2){
	if(x1<=x[1]) return 0;
	int i=upper_bound(x+1,x+nx+1,x1)-x-1;
	debug(i);
	return qry(roots[i],1,c,y1+1,y2,x1);
}
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	cin>>r>>c>>n>>q>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i][0]>>a[i][1]>>a[i][2]>>a[i][3];
		swap(a[i][1],a[i][2]);
		if(a[i][0]>a[i][1]) swap(a[i][0],a[i][1]);
		if(a[i][2]>a[i][3]) swap(a[i][2],a[i][3]);
		x[2*i-1]=a[i][0];
		x[2*i]=a[i][1];
		y[2*i-1]=a[i][2];
		y[2*i]=a[i][3];
	}
	sort(x+1,x+2*n+1); nx=unique(x+1,x+2*n+1)-x-1;
	//sort(y+1,y+2*n+1); ny=unique(y+1,y+2*n+1)-y-1;
	for(int i=1;i<=n;i++){
		a[i][0]=lower_bound(x+1,x+nx+1,a[i][0])-x;
		a[i][1]=lower_bound(x+1,x+nx+1,a[i][1])-x;
		//a[i][2]=lower_bound(y+1,y+ny+1,a[i][2])-y;
		//a[i][3]=lower_bound(y+1,y+ny+1,a[i][3])-y;
		ev1[a[i][0]].push_back({a[i][2],a[i][3]});
		ev2[a[i][1]].push_back({a[i][2],a[i][3]});
	}
	for(int i=1;i<=nx;i++){
		roots[i]=T.size(); T.emplace_back();
		T[roots[i]]=T[roots[i-1]];
		for(auto [l,r]: ev1[i]){
			int nroot=T.size(); T.emplace_back();
			debug(x[i],l,r,1);
			upd(roots[i],nroot,1,c,l+1,r,1,-x[i]);
			roots[i]=nroot;
		}
		for(auto [l,r]: ev2[i]){
			int nroot=T.size(); T.emplace_back();
			debug(x[i],l,r,-1);
			upd(roots[i],nroot,1,c,l+1,r,-1,x[i]);
			roots[i]=nroot;
		}
		debug(qry(roots[i],1,c,1,c,x[i]));
	}
	for(int t=1;t<=q;t++){
		ll x1,y1,x2,y2,v;
		cin>>x1>>y1>>x2>>y2>>v;
		v=prv*v%m;
		x1+=v; if(x1>=m) x1-=m;
		x2+=v; if(x2>=m) x2-=m;
		y1+=v; if(y1>=m) y1-=m;
		y2+=v; if(y2>=m) y2-=m;
		if(x1>x2) swap(x1,x2);
		if(y1>y2) swap(y1,y2);
		ll ans=solve(x2,y1,y2)-solve(x1,y1,y2);
		cout<<ans<<"\n";
		prv=ans;
	}
	return 0;
}

Compilation message

Main.cpp: In function 'll solve(int, int, int)':
Main.cpp:6:20: warning: statement has no effect [-Wunused-value]
    6 | #define debug(...) 42
      |                    ^~
Main.cpp:60:2: note: in expansion of macro 'debug'
   60 |  debug(i);
      |  ^~~~~
Main.cpp: In function 'int main()':
Main.cpp:6:20: warning: statement has no effect [-Wunused-value]
    6 | #define debug(...) 42
      |                    ^~
Main.cpp:91:4: note: in expansion of macro 'debug'
   91 |    debug(x[i],l,r,1);
      |    ^~~~~
Main.cpp:6:20: warning: statement has no effect [-Wunused-value]
    6 | #define debug(...) 42
      |                    ^~
Main.cpp:97:4: note: in expansion of macro 'debug'
   97 |    debug(x[i],l,r,-1);
      |    ^~~~~
Main.cpp:6:20: warning: statement has no effect [-Wunused-value]
    6 | #define debug(...) 42
      |                    ^~
Main.cpp:101:3: note: in expansion of macro 'debug'
  101 |   debug(qry(roots[i],1,c,1,c,x[i]));
      |   ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5776 KB Output is correct
2 Correct 3 ms 5776 KB Output is correct
3 Correct 3 ms 5776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5776 KB Output is correct
2 Correct 3 ms 5776 KB Output is correct
3 Correct 3 ms 5776 KB Output is correct
4 Correct 18 ms 15768 KB Output is correct
5 Correct 23 ms 15808 KB Output is correct
6 Correct 20 ms 15680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5776 KB Output is correct
2 Correct 3 ms 5776 KB Output is correct
3 Correct 3 ms 5776 KB Output is correct
4 Correct 18 ms 15768 KB Output is correct
5 Correct 23 ms 15808 KB Output is correct
6 Correct 20 ms 15680 KB Output is correct
7 Correct 239 ms 172784 KB Output is correct
8 Correct 488 ms 173864 KB Output is correct
9 Correct 329 ms 173152 KB Output is correct
10 Correct 437 ms 173784 KB Output is correct
11 Correct 305 ms 173996 KB Output is correct
12 Correct 358 ms 173600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5776 KB Output is correct
2 Correct 3 ms 5776 KB Output is correct
3 Correct 3 ms 5776 KB Output is correct
4 Correct 18 ms 15768 KB Output is correct
5 Correct 23 ms 15808 KB Output is correct
6 Correct 20 ms 15680 KB Output is correct
7 Correct 231 ms 173808 KB Output is correct
8 Correct 475 ms 174228 KB Output is correct
9 Correct 307 ms 173152 KB Output is correct
10 Correct 402 ms 174216 KB Output is correct
11 Correct 281 ms 174268 KB Output is correct
12 Correct 324 ms 174092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5776 KB Output is correct
2 Correct 3 ms 5776 KB Output is correct
3 Correct 3 ms 5776 KB Output is correct
4 Correct 18 ms 15768 KB Output is correct
5 Correct 23 ms 15808 KB Output is correct
6 Correct 20 ms 15680 KB Output is correct
7 Correct 239 ms 172784 KB Output is correct
8 Correct 488 ms 173864 KB Output is correct
9 Correct 329 ms 173152 KB Output is correct
10 Correct 437 ms 173784 KB Output is correct
11 Correct 305 ms 173996 KB Output is correct
12 Correct 358 ms 173600 KB Output is correct
13 Correct 231 ms 173808 KB Output is correct
14 Correct 475 ms 174228 KB Output is correct
15 Correct 307 ms 173152 KB Output is correct
16 Correct 402 ms 174216 KB Output is correct
17 Correct 281 ms 174268 KB Output is correct
18 Correct 324 ms 174092 KB Output is correct
19 Correct 438 ms 337892 KB Output is correct
20 Correct 687 ms 338408 KB Output is correct
21 Correct 466 ms 337316 KB Output is correct
22 Correct 591 ms 338444 KB Output is correct
23 Correct 330 ms 174192 KB Output is correct
24 Correct 528 ms 338124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 173 ms 90208 KB Output is correct
2 Correct 460 ms 173264 KB Output is correct
3 Correct 293 ms 173080 KB Output is correct
4 Correct 382 ms 173420 KB Output is correct
5 Correct 262 ms 91204 KB Output is correct
6 Correct 308 ms 173244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 173 ms 90208 KB Output is correct
2 Correct 460 ms 173264 KB Output is correct
3 Correct 293 ms 173080 KB Output is correct
4 Correct 382 ms 173420 KB Output is correct
5 Correct 262 ms 91204 KB Output is correct
6 Correct 308 ms 173244 KB Output is correct
7 Incorrect 467 ms 337988 KB Output isn't correct
8 Halted 0 ms 0 KB -