Submission #308080

# Submission time Handle Problem Language Result Execution time Memory
308080 2020-09-30T02:56:11 Z daniel920712 Game (IOI13_game) C++14
80 / 100
6424 ms 256004 KB
#include "game.h"
#include <stdio.h>
long long gcd2(long long X, long long Y) {
    long long tmp;
    while (X != Y && Y != 0) {
        tmp = X;
        X = Y;
        Y = tmp % Y;
    }
    return X;
}
struct A
{
    int nxl,nxr,nxt;
    long long con;
}Node[20000005];
long long N,M,now=1;
void New(int l,int r,int here,int t)
{
    Node[here].nxt=t;
    Node[here].nxl=-1;
    Node[here].nxr=-1;
    Node[here].con=0;
}
void init(int R, int C)
{
    N=R;
    M=C;
    New(0,N-1,0,-1);
}
void Merge(int here,int l,int r,int what,int lll,int rrr)
{
    int ll,rr;
    if(what==lll&&what==rrr)
    {
        Node[here].con=0;
        if(l!=-1) Node[here].con=gcd2(Node[here].con,Node[l].con);
        if(r!=-1) Node[here].con=gcd2(Node[here].con,Node[r].con);
        return;
    }
    if(what<=(lll+rrr)/2)
    {
        if(Node[here].nxl==-1)
        {
            Node[here].nxl=now++;
            New(lll,(lll+rrr)/2,Node[here].nxl,-2);
        }
        if(l!=-1) ll=Node[l].nxl;
        if(r!=-1) rr=Node[r].nxl;
        Merge(Node[here].nxl,ll,rr,what,lll,(lll+rrr)/2);
        Node[here].con=0;
        if(l!=-1) Node[here].con=gcd2(Node[here].con,Node[l].con);
        if(r!=-1) Node[here].con=gcd2(Node[here].con,Node[r].con);
    }
    else
    {
        if(Node[here].nxr==-1)
        {
            Node[here].nxr=now++;
            New((lll+rrr)/2+1,rrr,Node[here].nxr,-2);
        }
        if(l!=-1) ll=Node[l].nxr;
        if(r!=-1) rr=Node[r].nxr;
        Merge(Node[here].nxr,ll,rr,what,(lll+rrr)/2+1,rrr);
        Node[here].con=0;
        if(l!=-1) Node[here].con=gcd2(Node[here].con,Node[l].con);
        if(r!=-1) Node[here].con=gcd2(Node[here].con,Node[r].con);
    }
    //printf("%d %d %d\n",lll,rrr,Node[here].con);
}
void cha(int l,int r,int x,int y,long long con,int here)
{
    if(Node[here].nxt==-2)
    {
        if(y==l&&y==r)
        {
            Node[here].con=con;
            return;
        }
        if(y<=(l+r)/2)
        {
            if(Node[here].nxl==-1)
            {
                Node[here].nxl=now++;
                New(l,(l+r)/2,Node[here].nxl,-2);
            }
            cha(l,(l+r)/2,x,y,con,Node[here].nxl);
            Node[here].con=Node[Node[here].nxl].con;
            if(Node[here].nxr!=-1) Node[here].con=gcd2(Node[here].con,Node[Node[here].nxr].con);

        }
        else
        {
            if(Node[here].nxr==-1)
            {
                Node[here].nxr=now++;
                New((l+r)/2+1,r,Node[here].nxr,-2);
            }
            cha((l+r)/2+1,r,x,y,con,Node[here].nxr);
            Node[here].con=Node[Node[here].nxr].con;
            if(Node[here].nxl!=-1) Node[here].con=gcd2(Node[here].con,Node[Node[here].nxl].con);
        }
        //if(y==76) printf("%lld %lld %lld %lld\n",y,l,r,Node[here].con);
    }
    else
    {
        if(x==l&&x==r)
        {
            if(Node[here].nxt==-1)
            {
                Node[here].nxt=now++;
                New(0,M-1,Node[here].nxt,-2);
            }
            cha(0,M-1,x,y,con,Node[here].nxt);
            return;
        }
        if(x<=(l+r)/2)
        {
            if(Node[here].nxl==-1)
            {
                Node[here].nxl=now++;
                New(l,(l+r)/2,Node[here].nxl,-1);
            }
            cha(l,(l+r)/2,x,y,con,Node[here].nxl);
        }
        else
        {
            if(Node[here].nxr==-1)
            {
                Node[here].nxr=now++;
                New((l+r)/2+1,r,Node[here].nxr,-1);
            }
            cha((l+r)/2+1,r,x,y,con,Node[here].nxr);
        }
        if(Node[here].nxt==-1)
        {
            Node[here].nxt=now++;
            New(0,M-1,Node[here].nxt,-2);
        }
        //printf("aa %d %d\n",l,r);
        Merge(Node[here].nxt,Node[Node[here].nxl].nxt,Node[Node[here].nxr].nxt,y,0,M-1);
    }
}
long long Find(int l,int r,int x1,int y1,int x2,int y2,int here)
{
    //printf("%lld %lld %lld %lld %lld\n",x1,y1,x2,y2,here);
    if(here==-1) return 0;
    if(Node[here].nxt==-2)
    {
        if(l==x2&&r==y2)
        {
            //printf("%lld %lld %lld\n",x2,y2,Node[here].con);
            return Node[here].con;
        }
        if(y2<=(l+r)/2) return Find(l,(l+r)/2,x1,y1,x2,y2,Node[here].nxl);
        if(x2>(l+r)/2) return Find((l+r)/2+1,r,x1,y1,x2,y2,Node[here].nxr);
        return gcd2(Find(l,(l+r)/2,x1,y1,x2,(l+r)/2,Node[here].nxl),Find((l+r)/2+1,r,x1,y1,(l+r)/2+1,y2,Node[here].nxr));
    }
    else
    {
        if(l==x1&&r==y1) return Find(0,M-1,x1,y1,x2,y2,Node[here].nxt);
        if(y1<=(l+r)/2) return Find(l,(l+r)/2,x1,y1,x2,y2,Node[here].nxl);
        if(x1>(l+r)/2) return Find((l+r)/2+1,r,x1,y1,x2,y2,Node[here].nxr);
        return gcd2(Find(l,(l+r)/2,x1,(l+r)/2,x2,y2,Node[here].nxl),Find((l+r)/2+1,r,(l+r)/2+1,y1,x2,y2,Node[here].nxr));
    }
}
void update(int P, int Q, long long K)
{
    cha(0,N-1,P,Q,K,0);
}

long long calculate(int P, int Q, int U, int V)
{
    long long ans=0,i;
    //printf("aaa\n");
    ans=Find(0,N-1,P,U,Q,V,0);
    /*for(i=P;i<=U;i++)
    {
        ans=gcd2(ans,Find(i,i,Q,V,0));

        //if(P==60) printf("%lld %lld\n",i,Find(i,i,Q,V,0));


    }*/
    //printf("cc %lld\n",ans);
    return ans;
}

Compilation message

game.cpp: In function 'long long int calculate(int, int, int, int)':
game.cpp:174:21: warning: unused variable 'i' [-Wunused-variable]
  174 |     long long ans=0,i;
      |                     ^
game.cpp: In function 'void Merge(int, int, int, int, int, int)':
game.cpp:50:14: warning: 'll' may be used uninitialized in this function [-Wmaybe-uninitialized]
   50 |         Merge(Node[here].nxl,ll,rr,what,lll,(lll+rrr)/2);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
game.cpp:50:14: warning: 'rr' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 619 ms 10744 KB Output is correct
5 Correct 505 ms 10912 KB Output is correct
6 Correct 471 ms 7928 KB Output is correct
7 Correct 531 ms 7672 KB Output is correct
8 Correct 345 ms 5496 KB Output is correct
9 Correct 511 ms 7800 KB Output is correct
10 Correct 473 ms 7544 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1066 ms 13304 KB Output is correct
13 Correct 1780 ms 5320 KB Output is correct
14 Correct 309 ms 1016 KB Output is correct
15 Correct 2141 ms 6932 KB Output is correct
16 Correct 218 ms 14072 KB Output is correct
17 Correct 792 ms 9080 KB Output is correct
18 Correct 1422 ms 14584 KB Output is correct
19 Correct 1222 ms 14796 KB Output is correct
20 Correct 1127 ms 14200 KB Output is correct
21 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 595 ms 10744 KB Output is correct
13 Correct 496 ms 11128 KB Output is correct
14 Correct 465 ms 7804 KB Output is correct
15 Correct 544 ms 7736 KB Output is correct
16 Correct 348 ms 5624 KB Output is correct
17 Correct 509 ms 7672 KB Output is correct
18 Correct 474 ms 7544 KB Output is correct
19 Correct 1065 ms 13304 KB Output is correct
20 Correct 1752 ms 5092 KB Output is correct
21 Correct 311 ms 1000 KB Output is correct
22 Correct 2132 ms 7032 KB Output is correct
23 Correct 219 ms 13944 KB Output is correct
24 Correct 778 ms 9272 KB Output is correct
25 Correct 1411 ms 14516 KB Output is correct
26 Correct 1175 ms 14556 KB Output is correct
27 Correct 1085 ms 13984 KB Output is correct
28 Correct 851 ms 188968 KB Output is correct
29 Correct 2168 ms 210296 KB Output is correct
30 Correct 6424 ms 152916 KB Output is correct
31 Correct 5930 ms 117156 KB Output is correct
32 Correct 560 ms 1304 KB Output is correct
33 Correct 718 ms 3192 KB Output is correct
34 Correct 516 ms 207224 KB Output is correct
35 Correct 1337 ms 105336 KB Output is correct
36 Correct 2535 ms 207696 KB Output is correct
37 Correct 2083 ms 208120 KB Output is correct
38 Correct 2057 ms 207380 KB Output is correct
39 Correct 1734 ms 159608 KB Output is correct
40 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 612 ms 10616 KB Output is correct
13 Correct 516 ms 11000 KB Output is correct
14 Correct 460 ms 7800 KB Output is correct
15 Correct 569 ms 7548 KB Output is correct
16 Correct 351 ms 5620 KB Output is correct
17 Correct 511 ms 7544 KB Output is correct
18 Correct 471 ms 7160 KB Output is correct
19 Correct 1128 ms 13128 KB Output is correct
20 Correct 1817 ms 4960 KB Output is correct
21 Correct 333 ms 1016 KB Output is correct
22 Correct 2196 ms 6896 KB Output is correct
23 Correct 222 ms 14016 KB Output is correct
24 Correct 849 ms 9188 KB Output is correct
25 Correct 1467 ms 14352 KB Output is correct
26 Correct 1208 ms 14552 KB Output is correct
27 Correct 1114 ms 13776 KB Output is correct
28 Correct 814 ms 188988 KB Output is correct
29 Correct 2005 ms 210128 KB Output is correct
30 Correct 6209 ms 153012 KB Output is correct
31 Correct 5917 ms 116788 KB Output is correct
32 Correct 584 ms 1300 KB Output is correct
33 Correct 719 ms 3208 KB Output is correct
34 Correct 515 ms 207352 KB Output is correct
35 Correct 1375 ms 105496 KB Output is correct
36 Correct 2592 ms 207788 KB Output is correct
37 Correct 2245 ms 207764 KB Output is correct
38 Correct 2355 ms 207136 KB Output is correct
39 Runtime error 752 ms 256004 KB Execution killed with signal 9 (could be triggered by violating memory limits)
40 Halted 0 ms 0 KB -