Submission #963693

# Submission time Handle Problem Language Result Execution time Memory
963693 2024-04-15T13:34:59 Z simona1230 Game (IOI13_game) C++17
0 / 100
1 ms 600 KB
#include <bits/stdc++.h>
#include "game.h"
using namespace std;

int h,w;
long long x,y;
long long p,q,u,v;

struct segmentTree
{
    long long t[8000];
    segmentTree(){}

    long long query(long long i,long long l,long long r,long long ql,long long qr)
    {
        //cout<<l<<" -- "<<r<<endl;
        if(ql>qr)return 0;
        if(ql<=l&&r<=qr)return t[i];
        long long m=(l+r)/2;

        return __gcd(query(i*2,l,m,ql,min(qr,m)),query(i*2+1,m+1,r,max(ql,m+1),qr));
    }

    void update(long long i,long long l,long long r,long long idx,long long val)
    {
        //cout<<l<<" + "<<r<<endl;
        if(l==r)
        {
            t[i]=val;
            //cout<<l<<" + "<<r<<endl;
            return;
        }

        long long m=(l+r)/2;
        if(idx<=m)update(i*2,l,m,idx,val);
        else update(i*2+1,m+1,r,idx,val);

        t[i]=__gcd(t[i*2],t[i*2+1]);
        //cout<<l<<" + "<<r<<endl;
    }
};

struct twod
{
    segmentTree t[8000];
    twod(){}
    void update(int i,int l,int r,int x,int y,long long v)
    {
        //cout<<l<<" - "<<r<<endl;
        if(l==r)
        {
            t[i].update(1,0,w-1,y,v);
            //cout<<l<<" - "<<r<<endl;
            return;
        }

        int m=(l+r)/2;
        if(x<=m)update(i*2,l,m,x,y,v);
        else update(i*2+1,m+1,r,x,y,v);
        //cout<<l<<" - "<<r<<endl;
        long long val=__gcd(t[i*2].query(1,0,w-1,y,y),t[i*2+1].query(1,0,w-1,y,y));

        t[i].update(1,0,w-1,y,val);
    }

    int query(int i,int l,int r,int ql,int qr,int ql2,int qr2)
    {
        if(ql>qr)return 0;
        if(ql<=l&&r<=qr)
        {
            //cout<<l<<" "<<r<<endl;
            return t[i].query(1,0,w-1,ql2,qr2);
        }
        int m=(l+r)/2;
        return __gcd(query(i*2,l,m,ql,min(qr,m),ql2,qr2),query(i*2+1,m+1,r,max(ql,m+1),qr,ql2,qr2));
    }
};

twod t;

void init(int R,int C)
{
    h=R;
    w=C;
}

void update(int X,int Y,long long V)
{
    x=X;
    y=Y;
    v=V;
    t.update(1,0,h-1,x,y,v);
}

long long calculate(int P,int Q,int U,int V)
{
    p=P;
    q=Q;
    u=U;
    v=V;
    return t.query(1,0,h-1,p,u,q,v);
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -