답안 #667880

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
667880 2022-12-02T08:31:25 Z Register Svjetlost (COI18_svjetlost) C++14
69 / 100
594 ms 34032 KB
#include <bits/stdc++.h>
#define lc pos<<1
#define rc pos<<1|1
using namespace std;
using db=long double;
const int N=1e5+5,M=(1<<20)+5;
const db eps=1e-9,pi=acos(-1);
int n,q,pre[N],nxt[N];
db mx[M],tg[M];
vector<db> v;
struct vec{
	int x,y;
	void read() {scanf("%d%d",&x,&y);}
}p[N];
using cv=const vec&;
vec operator - (cv t1,cv t2) {return {t1.x-t2.x,t1.y-t2.y};}
db len(cv t) {return hypot(t.x,t.y);}
db ang(cv t) {return atan2(t.y,t.x);}
struct sb{
	db a,l;
	void init(cv t) {a=ang(t);l=len(t);}
}dl1[N],dl2[N],ad[N];
void upd(int l,int r,int pos,int L,int R,db x){
	if(L>R) return;
	if(L<=l&&r<=R) {mx[pos]+=x;tg[pos]+=x;return;}
	int mid=l+r>>1;
	if(L<=mid) upd(l,mid,lc,L,R,x);
	if(R>mid) upd(mid+1,r,rc,L,R,x);
	mx[pos]=max(mx[lc],mx[rc])+tg[pos];
}
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++) p[i].read(),nxt[i]=(i+1)%n,pre[i]=(i+n-1)%n;
	for(int i=0;i<n;i++) v.push_back(ang(p[(i+1)%n]-p[i]));
	scanf("%d",&q);
	for(int i=0,x;i<q;i++)
		scanf("%d",&x),x--,
		dl1[i].init(p[x]-p[pre[x]]),
		dl2[i].init(p[nxt[x]]-p[x]),
		ad[i].init(p[nxt[x]]-p[pre[x]]),
		v.push_back(ad[i].a),
		nxt[pre[x]]=nxt[x],
		pre[nxt[x]]=pre[x];
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end(),[](db x,db y){return fabs(x-y)<=eps;}),v.end());
	int m=v.size();
	auto pos=[&](db x) {return lower_bound(v.begin(),v.end(),x,[](db a,db b){return a<b-eps;})-v.begin();};
	auto add=[&](db x,db y){
		int t=pos(x)+1;
		if((x+=pi)>v.back()+eps) upd(1,m,1,t,m,y),t=1,x-=pi*2;
		upd(1,m,1,t,pos(x),y);
	};
	for(int i=0;i<n;i++) add(ang(p[(i+1)%n]-p[i]),len(p[(i+1)%n]-p[i]));
	printf("%.6Lf\n",mx[1]);
	for(int i=0;i<q;i++)
		add(dl1[i].a,-dl1[i].l),
		add(dl2[i].a,-dl2[i].l),
		add(ad[i].a,ad[i].l),
		printf("%.6Lf\n",mx[1]);
	return 0;
}

Compilation message

svjetlost.cpp: In function 'void upd(int, int, int, int, int, db)':
svjetlost.cpp:26:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   26 |  int mid=l+r>>1;
      |          ~^~
svjetlost.cpp: In function 'int main()':
svjetlost.cpp:32:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
svjetlost.cpp:35:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |  scanf("%d",&q);
      |  ~~~~~^~~~~~~~~
svjetlost.cpp:37:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |   scanf("%d",&x),x--,
      |   ~~~~~^~~~~~~~~
svjetlost.cpp: In member function 'void vec::read()':
svjetlost.cpp:13:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  void read() {scanf("%d%d",&x,&y);}
      |               ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB 11 numbers
2 Correct 1 ms 340 KB 41 numbers
3 Correct 1 ms 340 KB 11 numbers
4 Correct 1 ms 340 KB 93 numbers
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB 11 numbers
2 Correct 1 ms 340 KB 41 numbers
3 Correct 1 ms 340 KB 11 numbers
4 Correct 1 ms 340 KB 93 numbers
5 Correct 2 ms 468 KB 101 numbers
6 Correct 6 ms 852 KB 1201 numbers
7 Correct 8 ms 908 KB 1556 numbers
8 Correct 8 ms 980 KB 1996 numbers
9 Correct 8 ms 980 KB 1960 numbers
10 Correct 8 ms 980 KB 1991 numbers
11 Correct 8 ms 980 KB 1963 numbers
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB found '32934.3604540000', expected '32934.3604541195', error '0.0000000000'
2 Correct 2 ms 468 KB found '31571636.3365450017', expected '31571636.3365447633', error '0.0000000000'
3 Correct 12 ms 1760 KB found '31442617.6286690012', expected '31442617.6286691241', error '0.0000000000'
4 Correct 28 ms 3148 KB found '31424400.0534069985', expected '31424400.0534067489', error '0.0000000000'
5 Correct 99 ms 11332 KB found '3142086769.6889739037', expected '3142086769.6889681816', error '0.0000000000'
6 Correct 108 ms 11240 KB found '3142076120.8714599609', expected '3142076120.8714694977', error '0.0000000000'
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 892 KB 1001 numbers
2 Correct 73 ms 7232 KB 15001 numbers
3 Correct 201 ms 15860 KB 44445 numbers
4 Correct 185 ms 13964 KB 22223 numbers
5 Correct 408 ms 31144 KB 88889 numbers
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB 11 numbers
2 Correct 1 ms 340 KB 41 numbers
3 Correct 1 ms 340 KB 11 numbers
4 Correct 1 ms 340 KB 93 numbers
5 Correct 2 ms 468 KB 101 numbers
6 Correct 6 ms 852 KB 1201 numbers
7 Correct 8 ms 908 KB 1556 numbers
8 Correct 8 ms 980 KB 1996 numbers
9 Correct 8 ms 980 KB 1960 numbers
10 Correct 8 ms 980 KB 1991 numbers
11 Correct 8 ms 980 KB 1963 numbers
12 Correct 0 ms 340 KB found '32934.3604540000', expected '32934.3604541195', error '0.0000000000'
13 Correct 2 ms 468 KB found '31571636.3365450017', expected '31571636.3365447633', error '0.0000000000'
14 Correct 12 ms 1760 KB found '31442617.6286690012', expected '31442617.6286691241', error '0.0000000000'
15 Correct 28 ms 3148 KB found '31424400.0534069985', expected '31424400.0534067489', error '0.0000000000'
16 Correct 99 ms 11332 KB found '3142086769.6889739037', expected '3142086769.6889681816', error '0.0000000000'
17 Correct 108 ms 11240 KB found '3142076120.8714599609', expected '3142076120.8714694977', error '0.0000000000'
18 Correct 6 ms 892 KB 1001 numbers
19 Correct 73 ms 7232 KB 15001 numbers
20 Correct 201 ms 15860 KB 44445 numbers
21 Correct 185 ms 13964 KB 22223 numbers
22 Correct 408 ms 31144 KB 88889 numbers
23 Correct 594 ms 32472 KB 98175 numbers
24 Correct 131 ms 8728 KB 25905 numbers
25 Correct 477 ms 32388 KB 98169 numbers
26 Incorrect 444 ms 34032 KB 40842nd numbers differ - expected: '3728194663.4741077423', found: '3728119835.3530569077', error = '0.0000200709'
27 Halted 0 ms 0 KB -