답안 #384129

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
384129 2021-03-31T14:14:42 Z alishahali1382 게임 (IOI13_game) C++14
0 / 100
2 ms 364 KB
#include "game.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define debug(x) {cerr<<#x<<"="<<x<<"\n";}
#define debug2(x, y) {cerr<<#x<<", "<<#y<<" = "<<x<<", "<<y<<"\n";}
#define debugp(p) {cerr<<#p" = {"<<p.first<<", "<<p.second<<"}\n";}
#define pb push_back
#define all(x) x.begin(), x.end()

ll gcd2(ll X, ll Y) {
    ll tmp;
    while (X != Y && Y != 0) {
        tmp = X;
        X = Y;
        Y = tmp % Y;
    }
    return X;
}

const int SEGSZ=7000000, SEGSZ2=300000;

ll seg[SEGSZ], ans;
int L[SEGSZ], R[SEGSZ], ts;
int Set(int id, int tl, int tr, int pos, ll val){
    if (!id) id=++ts;
    if (tr-tl==1){
        seg[id]=val;
        return id;
    }
    int mid=(tl+tr)>>1;
    if (pos<mid) L[id]=Set(L[id], tl, mid, pos, val);
    else R[id]=Set(R[id], mid, tr, pos, val);
    seg[id]=gcd2(seg[L[id]], seg[R[id]]);
    return id;
}
void Get(int id, int tl, int tr, int l, int r){
    if (r<=tl || tr<=l || !id) return ;
    if (l<=tl && tr<=r){
        ans=gcd2(ans, seg[id]); // overall log(10^18) for single query of problem
        return ;
    }
    int mid=(tl+tr)>>1;
    Get(L[id], tl, mid, l, r);
    Get(R[id], mid, tr, l, r);
}

int n, m, root;
int seg2[SEGSZ2], L2[SEGSZ2], R2[SEGSZ2], ts2;
int Set2(int id, int tl, int tr, int x, int y, ll val){
    if (!id) id=++ts2;
    seg2[id]=Set(seg2[id], 0, m, y, val);
    if (tr-tl==1) return id;
    int mid=(tl+tr)>>1;
    if (x<mid) L2[id]=Set2(L2[id], tl, mid, x, y, val);
    else R2[id]=Set2(R2[id], mid, tr, x, y, val);
    return id;
}
void Get2(int id, int tl, int tr, int l1, int r1, int l2, int r2){
    if (r1<=tl || tr<=l1) return ;
    if (l1<=tl && tr<=r1){
        Get(seg2[id], 0, m, l2, r2);
        return ;
    }
    int mid=(tl+tr)>>1;
    Get2(L2[id], tl, mid, l1, r1, l2, r2);
    Get2(R2[id], mid, tr, l1, r1, l2, r2);
}

void init(int nn, int mm) {
    n=nn;
    m=mm;
}

void update(int P, int Q, ll K) {
    root=Set2(root, 0, n, P, Q, K);
}

ll calculate(int P, int Q, int U, int V) {
    ans=0;
    Get2(root, 0, n, P, U+1, Q, V+1);
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 2 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -