답안 #64709

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
64709 2018-08-05T12:30:07 Z TadijaSebez 게임 (IOI13_game) C++11
100 / 100
11473 ms 166748 KB
#include "game.h"
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <ctime>
using namespace std;
#define mp make_pair
#define ll long long
const int N=200050;
const int M=N*64*2;
ll gcd(ll x, ll y){ return __gcd(x,y);}
int ls[M],rs[M],root,tsz,rt[M],y[M],L[M],R[M];
pair<int,int> id[M];
ll val[M],my[M];
int MakeNode(pair<int,int> p, ll g)
{
	tsz++;
	y[tsz]=rand();
	my[tsz]=val[tsz]=g;
	L[tsz]=R[tsz]=p.first;
	id[tsz]=p;
	return tsz;
}
void Take(int c)
{
	if(!c) return;
	val[c]=my[c];
	L[c]=id[c].first;
	R[c]=id[c].first;
	if(ls[c]) val[c]=gcd(val[c],val[ls[c]]),L[c]=L[ls[c]];
	if(rs[c]) val[c]=gcd(val[c],val[rs[c]]),R[c]=R[rs[c]];
}
void Rotate1(int &c)
{
	int a=ls[c],b=rs[a];
	ls[c]=b;
	rs[a]=c;
	Take(c);Take(a);
	c=a;
}
void Rotate2(int &c)
{
	int a=rs[c],b=ls[a];
	rs[c]=b;
	ls[a]=c;
	Take(c);Take(a);
	c=a;
}
void Add(int &c, pair<int,int> p, ll g)
{
	if(!c){ c=MakeNode(p,g);return;}
	if(p==id[c])
	{
		my[c]=g;
		Take(c);
	}
	else if(p<id[c])
	{
		Add(ls[c],p,g);
		if(y[ls[c]]>y[c]) Rotate1(c);
		else Take(c);
	}
	else
	{
		Add(rs[c],p,g);
		if(y[rs[c]]>y[c]) Rotate2(c);
		else Take(c);
	}
}
ll Get(int c, int l, int r)
{
	if(!c || L[c]>r || R[c]<l) return 0;
	if(l<=L[c] && r>=R[c]) return val[c];
	ll ans=0;
	if(id[c].first>=l && id[c].first<=r) ans=my[c];
	ans=gcd(ans,Get(ls[c],l,r));
	ans=gcd(ans,Get(rs[c],l,r));
	return ans;
}
void Set(int &c, int ss, int se, int x, int y, ll g)
{
	if(!c) c=++tsz;
	Add(rt[c],mp(y,x),g);
	if(ss==se) return;
	int mid=ss+se>>1;
	if(x<=mid) Set(ls[c],ss,mid,x,y,g);
	else Set(rs[c],mid+1,se,x,y,g);
}
ll Get(int c, int ss, int se, int qs, int qe, int l, int r)
{
	if(!c || ss>qe || qs>se) return 0;
	if(qs<=ss && qe>=se) return Get(rt[c],l,r);
	int mid=ss+se>>1;
	return gcd(Get(ls[c],ss,mid,qs,qe,l,r),Get(rs[c],mid+1,se,qs,qe,l,r));
}
int n,m;
void init(int R, int C){ srand(time(0));n=R;m=C;}
void update(int x, int y, ll g){ Set(root,0,n-1,x,y,g);}
void Swap(int &a, int &b){ a^=b,b^=a,a^=b;}
ll calculate(int x1, int y1, int x2, int y2){ if(x1>x2) Swap(x1,x2);if(y1>y2) Swap(y1,y2);return Get(root,0,n-1,x1,x2,y1,y2);}

Compilation message

grader.c: In function 'int main()':
grader.c:18:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
  int res;
      ^~~
game.cpp: In function 'void Set(int&, int, int, int, int, long long int)':
game.cpp:86:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=ss+se>>1;
          ~~^~~
game.cpp: In function 'long long int Get(int, int, int, int, int, int, int)':
game.cpp:94:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=ss+se>>1;
          ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 4 ms 612 KB Output is correct
3 Correct 3 ms 612 KB Output is correct
4 Correct 2 ms 612 KB Output is correct
5 Correct 3 ms 612 KB Output is correct
6 Correct 5 ms 648 KB Output is correct
7 Correct 3 ms 648 KB Output is correct
8 Correct 3 ms 648 KB Output is correct
9 Correct 4 ms 648 KB Output is correct
10 Correct 4 ms 648 KB Output is correct
11 Correct 6 ms 648 KB Output is correct
12 Correct 3 ms 648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 648 KB Output is correct
2 Correct 2 ms 648 KB Output is correct
3 Correct 3 ms 648 KB Output is correct
4 Correct 1556 ms 11068 KB Output is correct
5 Correct 486 ms 15216 KB Output is correct
6 Correct 1352 ms 16632 KB Output is correct
7 Correct 1607 ms 21264 KB Output is correct
8 Correct 853 ms 25068 KB Output is correct
9 Correct 1257 ms 30056 KB Output is correct
10 Correct 1487 ms 34336 KB Output is correct
11 Correct 3 ms 34336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 34336 KB Output is correct
2 Correct 3 ms 34336 KB Output is correct
3 Correct 3 ms 34336 KB Output is correct
4 Correct 2 ms 34336 KB Output is correct
5 Correct 3 ms 34336 KB Output is correct
6 Correct 3 ms 34336 KB Output is correct
7 Correct 3 ms 34336 KB Output is correct
8 Correct 4 ms 34336 KB Output is correct
9 Correct 3 ms 34336 KB Output is correct
10 Correct 3 ms 34336 KB Output is correct
11 Correct 4 ms 34336 KB Output is correct
12 Correct 2151 ms 45260 KB Output is correct
13 Correct 4361 ms 45260 KB Output is correct
14 Correct 529 ms 45412 KB Output is correct
15 Correct 4655 ms 54264 KB Output is correct
16 Correct 529 ms 59776 KB Output is correct
17 Correct 1745 ms 62148 KB Output is correct
18 Correct 3862 ms 70400 KB Output is correct
19 Correct 2882 ms 75756 KB Output is correct
20 Correct 3033 ms 80508 KB Output is correct
21 Correct 3 ms 80508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 80508 KB Output is correct
2 Correct 3 ms 80508 KB Output is correct
3 Correct 4 ms 80508 KB Output is correct
4 Correct 2 ms 80508 KB Output is correct
5 Correct 3 ms 80508 KB Output is correct
6 Correct 2 ms 80508 KB Output is correct
7 Correct 3 ms 80508 KB Output is correct
8 Correct 3 ms 80508 KB Output is correct
9 Correct 3 ms 80508 KB Output is correct
10 Correct 3 ms 80508 KB Output is correct
11 Correct 4 ms 80508 KB Output is correct
12 Correct 1207 ms 84376 KB Output is correct
13 Correct 488 ms 85200 KB Output is correct
14 Correct 1079 ms 85200 KB Output is correct
15 Correct 1433 ms 85200 KB Output is correct
16 Correct 747 ms 85200 KB Output is correct
17 Correct 1412 ms 85200 KB Output is correct
18 Correct 1399 ms 85200 KB Output is correct
19 Correct 2128 ms 88068 KB Output is correct
20 Correct 4744 ms 88068 KB Output is correct
21 Correct 441 ms 88068 KB Output is correct
22 Correct 4688 ms 88068 KB Output is correct
23 Correct 495 ms 88068 KB Output is correct
24 Correct 1891 ms 88068 KB Output is correct
25 Correct 4396 ms 88068 KB Output is correct
26 Correct 3537 ms 88068 KB Output is correct
27 Correct 3194 ms 88068 KB Output is correct
28 Correct 965 ms 102392 KB Output is correct
29 Correct 3615 ms 105564 KB Output is correct
30 Correct 6892 ms 105564 KB Output is correct
31 Correct 5340 ms 105564 KB Output is correct
32 Correct 864 ms 105564 KB Output is correct
33 Correct 1215 ms 105564 KB Output is correct
34 Correct 605 ms 105564 KB Output is correct
35 Correct 2583 ms 105564 KB Output is correct
36 Correct 6144 ms 105564 KB Output is correct
37 Correct 4051 ms 105564 KB Output is correct
38 Correct 4531 ms 105564 KB Output is correct
39 Correct 3513 ms 105564 KB Output is correct
40 Correct 2 ms 105564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 105564 KB Output is correct
2 Correct 4 ms 105564 KB Output is correct
3 Correct 3 ms 105564 KB Output is correct
4 Correct 3 ms 105564 KB Output is correct
5 Correct 3 ms 105564 KB Output is correct
6 Correct 3 ms 105564 KB Output is correct
7 Correct 3 ms 105564 KB Output is correct
8 Correct 3 ms 105564 KB Output is correct
9 Correct 4 ms 105564 KB Output is correct
10 Correct 3 ms 105564 KB Output is correct
11 Correct 4 ms 105564 KB Output is correct
12 Correct 1245 ms 105564 KB Output is correct
13 Correct 499 ms 105564 KB Output is correct
14 Correct 1280 ms 105564 KB Output is correct
15 Correct 1543 ms 105564 KB Output is correct
16 Correct 797 ms 105564 KB Output is correct
17 Correct 1464 ms 105564 KB Output is correct
18 Correct 1445 ms 105564 KB Output is correct
19 Correct 2226 ms 105564 KB Output is correct
20 Correct 4301 ms 105564 KB Output is correct
21 Correct 499 ms 105564 KB Output is correct
22 Correct 4740 ms 105564 KB Output is correct
23 Correct 610 ms 105564 KB Output is correct
24 Correct 1665 ms 105564 KB Output is correct
25 Correct 4405 ms 105564 KB Output is correct
26 Correct 3002 ms 105564 KB Output is correct
27 Correct 3027 ms 105564 KB Output is correct
28 Correct 997 ms 114576 KB Output is correct
29 Correct 4128 ms 117764 KB Output is correct
30 Correct 6793 ms 117764 KB Output is correct
31 Correct 5402 ms 117764 KB Output is correct
32 Correct 1026 ms 117764 KB Output is correct
33 Correct 1350 ms 117764 KB Output is correct
34 Correct 767 ms 117764 KB Output is correct
35 Correct 2641 ms 117764 KB Output is correct
36 Correct 6296 ms 117764 KB Output is correct
37 Correct 4377 ms 117764 KB Output is correct
38 Correct 4731 ms 117972 KB Output is correct
39 Correct 1355 ms 144288 KB Output is correct
40 Correct 6726 ms 146348 KB Output is correct
41 Correct 11473 ms 146348 KB Output is correct
42 Correct 9312 ms 146348 KB Output is correct
43 Correct 1382 ms 146348 KB Output is correct
44 Correct 1443 ms 146348 KB Output is correct
45 Correct 3619 ms 146348 KB Output is correct
46 Correct 9420 ms 146348 KB Output is correct
47 Correct 9043 ms 156064 KB Output is correct
48 Correct 9065 ms 166748 KB Output is correct
49 Correct 3 ms 166748 KB Output is correct