Submission #40650

# Submission time Handle Problem Language Result Execution time Memory
40650 2018-02-06T15:37:04 Z top34051 Game (IOI13_game) C++14
0 / 100
3 ms 888 KB
#include "game.h"
#include<bits/stdc++.h>
using namespace std;

#define ll long long
const int maxn = 1e7 + 5;

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

class segtree {
public:
    int R, C, sz = 1;
    int rec[maxn][3];
    ll seg[maxn];

    int get(int pos, int dir) {
        if(!rec[pos][dir]) rec[pos][dir] = ++sz;
        return rec[pos][dir];
    }
    void row_update(int pos, int l, int r, int x, int y, ll val) {
//        printf("row_update [%d, %d] : (%d, %d) val = %lld\n",l,r,x,y,val);
        col_update(get(pos,2), 1, C, y, val);
        if(l==r) return ;
        int mid = (l+r)/2;
        if(x<=mid) row_update(get(pos,0), l, mid, x, y, val);
        else row_update(get(pos,1), mid+1, r, x, y, val);
    }
    void col_update(int pos, int l, int r, int x, ll val) {
//        printf("------- col_update [%d, %d] : (%d) val = %lld\n",l,r,x,val);
        if(l==r) {
            seg[pos] = val;
            return ;
        }
        int mid = (l+r)/2;
        if(x<=mid) col_update(get(pos,0), l, mid, x, val);
        else col_update(get(pos,1), mid+1, r, x, val);
        seg[pos] = gcd2(seg[get(pos,0)], seg[get(pos,1)]);
    }
    ll row_query(int pos, int l, int r, int r1, int r2, int c1, int c2) {
        if(l>r || r<r1 || r2<l) return 0;
        if(r1<=l && r<=r2) return col_query(get(pos,2), 1, C, c1, c2);
        int mid = (l+r)/2;
        ll res = 0;
        if(mid>=r1) res = gcd2(res, row_query(get(pos,0), l, mid, r1, r2, c1, c2));
        if(mid+1<=r2) res = gcd2(res, row_query(get(pos,1), mid+1, r, r1, r2, c1, c2));
        return res;
    }
    ll col_query(int pos, int l, int r, int x, int y) {
        if(l>r || r<x || y<l) return 0;
        if(x<=l && r<=y) return seg[pos];
        int mid = (l+r)/2;
        ll res = 0;
        if(mid>=x) res = gcd2(res, col_query(get(pos,0), l, mid, x, y));
        if(mid+1<=y) res = gcd2(res, col_query(get(pos,1), mid+1, r, x, y));
        return res;
    }
    void update(int x, int y, ll val) {
        row_update(1, 1, R, x, y, val);
    }
    ll query(int r1, int r2, int c1, int c2) {
        return row_query(1, 1, R, r1, r2, c1, c2);
    }
};

segtree tree;

void init(int R, int C) {
    tree.R = R;
    tree.C = C;
}

void update(int P, int Q, ll K) {
    tree.update(P+1, Q+1, K);
}

long long calculate(int P, int Q, int U, int V) {
    return tree.query(P+1, U+1, Q+1, V+1);
}

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;
      ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 376 KB Output is correct
2 Incorrect 3 ms 492 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 492 KB Output is correct
2 Incorrect 2 ms 492 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 496 KB Output is correct
2 Incorrect 3 ms 696 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 696 KB Output is correct
2 Incorrect 2 ms 756 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 756 KB Output is correct
2 Incorrect 2 ms 888 KB Output isn't correct
3 Halted 0 ms 0 KB -