답안 #331857

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
331857 2020-11-30T13:01:54 Z aryan12 게임 (IOI13_game) C++17
27 / 100
844 ms 78188 KB
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
const long long N = 2000;
vector<long long> seg[N * 3 + 2];
long long row, col;

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;
}

void init(int R, int C) {
    row = R;
    col = C;
    for(long long i = 0; i <= R * 3; i++) {
        seg[i].resize(C * 3 + 1, 0);
    }
}

void updateY(long long l, long long r, long long xpos, long long pos, long long xl, long long xr, long long q, long long val) {
    if(l == r) {
        if(xl == xr) {
            seg[xpos][pos] = val;
            return;
        }
        else {
            seg[xpos][pos] = gcd2(seg[xpos * 2][pos], seg[xpos * 2 + 1][pos]);
            return;
        }
    }
    long long mid = (l + r) / 2;
    if(q <= mid)
        updateY(l, mid, xpos, pos * 2, xl, xr, q, val);
    else
        updateY(mid + 1, r, xpos, pos * 2 + 1, xl, xr, q, val);
    seg[xpos][pos] = gcd2(seg[xpos][pos * 2], seg[xpos][pos * 2 + 1]);
}

void updateX(long long l, long long r, long long pos, long long ymax, long long p, long long q, long long val) {
    if(l != r) {
        long long mid = (l + r) / 2;
        if(p <= mid)
            updateX(l, mid, pos * 2, ymax, p, q, val);
        else
            updateX(mid + 1, r, pos * 2 + 1, ymax, p, q, val);
    }
    updateY(1, ymax, pos, 1, l, r, q, val);
}

void update(int P, int Q, long long K) {
    P++;
    Q++;
    updateX(1, row, 1, col, P, Q, K);
}

long long calculateY(long long l, long long r, long long pos, long long U, long long V, long long xpos) {
    if(U <= l && r <= V) {
        return seg[xpos][pos];
    }
    if(U > r || V < l)
        return 0;
    long long mid = (l + r) / 2;
    return gcd2(calculateY(l, mid, pos * 2, U, V, xpos), calculateY(mid + 1, r, pos * 2 + 1, U, V, xpos));
}

long long calculateX(long long l, long long r, long long pos, long long ymax, long long P, long long Q, long long U, long long V) {
    if(P <= l && r <= Q) {
        return calculateY(1, ymax, 1, U, V, pos);
    }
    if(P > r || Q < l)
        return 0;
    long long mid = (l + r) / 2;
    return gcd2(calculateX(l, mid, pos * 2, ymax, P, Q, U, V), calculateX(mid + 1, r, pos * 2 + 1, ymax, P, Q, U, V));

}

long long calculate(int P, int Q, int U, int V) {
    P++;
    Q++;
    U++;
    V++;
    swap(Q, U);
    return calculateX(1, row, 1, col, P, Q, U, V);
}
/*
int main() {
    cout << "Input R and C" << endl;
    long long R, C;
    cin >> R >> C;
    init(R, C);
    cout << "Input the number of queries (Q)" << endl;
    long long Q;
    cin >> Q;
    for(long long i = 1; i <= Q; i++) {
        cout << "Enter 1 for Update, 2 for Calculate" << endl;
        long long command;
        cin >> command;
        if(command == 1) {
            cout << "Enter 2 integers(R, C) + 1 integer (val)" << endl;
            long long qr, qc, val;
            cin >> qr >> qc >> val;
            update(qr, qc, val);
            cout << "The segment tree after this operation looks like this" << endl;
            for(long long i = 1; i <= row * 4; i++) {
                for(long long j = 1; j <= col * 4; j++) {
                    cout << seg[i][j] << " ";
                }
                cout << endl;
            }
        }
        else {
            cout << "Enter 4 integers (R1, C1) (R2, C2)" << endl;
            long long qrl, qrr, qcl, qcr;
            cin >> qrl >> qrr >> qcl >> qcr;
            cout << "Answer = " << calculate(qrl, qrr, qcl, qcr) << endl;
        }
    }
}
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 2 ms 1132 KB Output is correct
3 Correct 2 ms 1132 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 1132 KB Output is correct
6 Correct 1 ms 1132 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Runtime error 2 ms 1132 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 844 ms 77704 KB Output is correct
5 Correct 564 ms 78188 KB Output is correct
6 Correct 737 ms 74680 KB Output is correct
7 Correct 738 ms 74384 KB Output is correct
8 Correct 642 ms 75244 KB Output is correct
9 Correct 741 ms 74476 KB Output is correct
10 Correct 686 ms 73964 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 1132 KB Output is correct
3 Correct 1 ms 1132 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 3 ms 1132 KB Output is correct
6 Correct 1 ms 1132 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Runtime error 2 ms 1132 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 1132 KB Output is correct
3 Correct 1 ms 1132 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 1132 KB Output is correct
6 Correct 1 ms 1132 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Runtime error 2 ms 1132 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 2 ms 1132 KB Output is correct
3 Correct 1 ms 1132 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 1132 KB Output is correct
6 Correct 1 ms 1132 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Runtime error 2 ms 1132 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Halted 0 ms 0 KB -