Submission #330063

# Submission time Handle Problem Language Result Execution time Memory
330063 2020-11-23T15:58:15 Z wiwiho Game (IOI13_game) C++14
0 / 100
166 ms 256004 KB
#include "game.h"

#include <bits/stdc++.h>
#include <bits/extc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define ef(a) emplace_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define iceil(a, b) (((a) + (b) - 1) / (b))
#define tomax(a, b) ((a) = max((a), (b)))
#define tomin(a, b) ((a) = min((a), (b)))
#define topos(a) ((a) = (((a) % MOD + MOD) % MOD))
#define uni(a) a.resize(unique(iter(a)) - a.begin())
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.F << ',' << p.S << ')';
}

struct Node2D{
    int l = -1, r = -1, rt = -1;
};

struct Node1D{
    int l = -1, r = -1;
    ll v = 0;
};

vector<Node2D> st2d(1e7);
vector<Node1D> st1d(1e7);
int ts1d = 0, ts2d = 1;

int n, m;

void pull(int id){
    auto &st = st1d;
    if(st[id].l == -1 && st[id].r == -1) return;
    else if(st[id].l == -1) st[id].v = st[st[id].r].v;
    else if(st[id].r == -1) st[id].v = st[st[id].l].v;
    else st[id].v = __gcd(st[st[id].l].v, st[st[id].r].v);
//    cerr << "pull1d " << id << " " << (st[id].l == -1 ? 0 : st[st[id].l].v) << " " << (st[id].r == -1 ? 0 : st[st[id].r].v) << " " << st[id].v << "\n";
}

int modify1D(int pos, ll v, int L, int R, int id){
    auto &st = st1d;
    if(id == -1) id = ts1d++;
//    cerr << "modify1D " << pos << " " << v << " " << L << " " << R << " " << id << "\n";
    if(L == R){
        st[id].v = v;
        return id;
    }
    int M = (L + R) / 2;
    if(pos <= M) st[id].l = modify1D(pos, v, L, M, st[id].l);
    else st[id].r = modify1D(pos, v, M + 1, R, st[id].r);
    pull(id);
    return id;
}

ll query1D(int l, int r, int L, int R, int id){
//    cerr << "query1D " << l << " " << r << " " << L << " " << R << " " << id << " " << (id == -1 ? 0 : st1d[id].v) << "\n";
    if(id == -1) return 0;
    auto &st = st1d;
    if(l == L && r == R){
        return st[id].v;
    }
    int M = (L + R) / 2;
    if(r <= M) return query1D(l, r, L, M, st[id].l);
    else if(l > M) return query1D(l, r, M + 1, R, st[id].r);
    else return __gcd(query1D(l, M, L, M, st[id].l), query1D(M + 1, r, M + 1, R, st[id].r));
}

void pull(int id, int y){
//    cerr << "pull2d " << id << " " << y << "\n";
    auto &st = st2d;
    if(st[id].l == -1 && st[id].r == -1) return;
    else if(st[id].l == -1) st[id].rt = modify1D(y, query1D(y, y, 1, m, st[st[id].r].rt), 1, m, st[id].rt);
    else if(st[id].r == -1) st[id].rt = modify1D(y, query1D(y, y, 1, m, st[st[id].l].rt), 1, m, st[id].rt);
    else st[id].rt = modify1D(y, __gcd(query1D(y, y, 1, m, st[st[id].l].rt), query1D(y, y, 1, m, st[st[id].r].rt)), 1, m, st[id].rt);
}

int modify2D(int x, int y, ll v, int L, int R, int id){
    auto& st = st2d;
    if(id == -1) id = ts2d++;
//    cerr << "modify2D " << x << " " << y << " " << v << " " << L << " " << R << " " << id << "\n";
    if(L == R){
        st[id].rt = modify1D(y, v, 1, m, st[id].rt);
        return id;
    }
    int M = (L + R) / 2;
    if(x <= M) st[id].l = modify2D(x, y, v, L, M, st[id].l);
    else st[id].r = modify2D(x, y, v, M + 1, R, st[id].r);
    pull(id, y);
    return id;
}

ll query2D(int x1, int y1, int x2, int y2, int L, int R, int id){
//    cerr << "query2D " << x1 << " " << y1 << " " << x2 << " " << y2 << " " << L << " " << R << " " << id << "\n";
    if(id == -1) return 0;
    auto &st = st2d;
    if(L == x1 && R == x2){
        return query1D(y1, y2, 1, m, st[id].rt);
    }
    int M = (L + R) / 2;
    if(x2 <= M) return query2D(x1, y1, x2, y2, L, M, st[id].l);
    else if(x1 > M) return query2D(x1, y1, x2, y2, M + 1, R, st[id].r);
    else{
        return __gcd(query2D(x1, y1, M, y2, L, M, st[id].l), query2D(M + 1, y1, x2, y2, M + 1, R, st[id].r));
    }
}

void init(int R, int C) {
    n = R;
    m = C;
}

void update(int P, int Q, long long K) {
//    cerr << "upd " << P << " " << Q << " " << K << "\n";
    P++; Q++;
    modify2D(P, Q, K, 1, n, 0);
}

long long calculate(int P, int Q, int U, int V) {
//    cerr << "qry " << P << " " << Q << " " << U << " " << V << "\n";
    P++; Q++; U++; V++;
    return query2D(P, Q, U, V, 1, n, 0);
}
# Verdict Execution time Memory Grader output
1 Runtime error 165 ms 256004 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 165 ms 256004 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 166 ms 256004 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 165 ms 256004 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 164 ms 256004 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -