Submission #1087612

# Submission time Handle Problem Language Result Execution time Memory
1087612 2024-09-13T02:45:42 Z Zero_OP Game (IOI13_game) C++14
80 / 100
2783 ms 256000 KB
#ifndef LOCAL
#include "game.h"
#endif //LOCAL

#include <bits/stdc++.h>

using namespace std;

#define sz(v) (int)v.size()
#define all(v) begin(v), end(v)
#define compact(v) v.erase(unique(all(v)), end(v))
#define dbg(x) "[" #x " = " << (x) << "]"

template<typename T>
    bool minimize(T& a, const T& b){
        if(a > b) return a = b, true;
        return false;
    }

template<typename T>
    bool maximize(T& a, const T& b){
        if(a < b) return a = b, true;
        return false;
    }

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;


long long gcd2(long long X, long long Y) {
//    cout << X << ' ' << Y << '\n';
    long long tmp;
    while (X != Y && Y != 0) {
        tmp = X;
        X = Y;
        Y = tmp % Y;
    }
    return X;
}

const int MAX = 4e7 + 5;
int N, M, tree2D, lt[MAX], rt[MAX], id[MAX], num;
long long st[MAX];

void define(int& x){
    if(x == 0) x = ++num;
}

void update_y(int& idx, int lx, int rx, int tl, int tr, int& idy, int ly, int ry, int y, long long k){
    define(idy);

    if(ly == ry){
        if(lx == rx) st[idy] = k;
        else st[idy] = gcd2(st[tl], st[tr]);
    } else{
        int mid = (ly + ry) >> 1;
        if(y <= mid) update_y(idx, lx, rx, lt[tl], lt[tr], lt[idy], ly, mid, y, k);
        else update_y(idx, lx, rx, rt[tl], rt[tr], rt[idy], mid + 1, ry, y, k);

        st[idy] = gcd2(st[lt[idy]], st[rt[idy]]);
    }
}

void update_x(int& idx, int lx, int rx, int x, int y, long long k){
    define(idx);

    if(lx < rx){
        int mid = lx + rx >> 1;
        if(x <= mid) update_x(lt[idx], lx, mid, x, y, k);
        else update_x(rt[idx], mid + 1, rx, x, y, k);
    }

    update_y(idx, lx, rx, id[lt[idx]], id[rt[idx]], id[idx], 0, M - 1, y, k);
}

long long query_y(int& idy, int ly, int ry, int u, int v){
    if((u <= ly && ry <= v) || idy == 0) return st[idy];
    int mid = ly + ry >> 1;
    long long g = 0;
    if(u <= mid) g = gcd2(g, query_y(lt[idy], ly, mid, u, v));
    if(mid < v) g = gcd2(g, query_y(rt[idy], mid + 1, ry, u, v));
    return g;
}

long long query_x(int& idx, int lx, int rx, int u, int v, int p, int q){
    if((u <= lx && rx <= v) || idx == 0) return query_y(id[idx], 0, M - 1, p, q);
     int mid = lx + rx >> 1;
     long long g = 0;
     if(u <= mid) g = gcd2(g, query_x(lt[idx], lx, mid, u, v, p, q));
     if(mid < v) g = gcd2(g, query_x(rt[idx], mid + 1, rx, u, v, p, q));
     return g;
}

void init(int R, int C) {
    N = R;
    M = C;
}

void update(int P, int Q, long long K) {
    update_x(tree2D, 0, N - 1, P, Q, K);
}

long long calculate(int P, int Q, int U, int V) {
    return query_x(tree2D, 0, N - 1, P, U, Q, V);
}


#ifdef LOCAL
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

    #define filename "task"
    if(fopen(filename".inp", "r")){
        freopen(filename".inp", "r", stdin);
        freopen(filename".out", "w", stdout);
    }

    int Q;
    cin >> N >> M >> Q;

    init(N, M);

    while(Q--){
        int type;
        cin >> type;
        if(type == 1){
            int x, y; long long z;
            cin >> x >> y >> z;
            update(x, y, z);
        } else{
            int p, q, u, v;
            cin >> p >> q >> u >> v;
            cout << calculate(p, q, u, v) << '\n';
        }
    }


    return 0;
}
#endif // LOCAL

Compilation message

game.cpp: In function 'void update_x(int&, int, int, int, int, long long int)':
game.cpp:70:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   70 |         int mid = lx + rx >> 1;
      |                   ~~~^~~~
game.cpp: In function 'long long int query_y(int&, int, int, int, int)':
game.cpp:80:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   80 |     int mid = ly + ry >> 1;
      |               ~~~^~~~
game.cpp: In function 'long long int query_x(int&, int, int, int, int, int, int)':
game.cpp:89:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   89 |      int mid = lx + rx >> 1;
      |                ~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 298 ms 8472 KB Output is correct
5 Correct 202 ms 8816 KB Output is correct
6 Correct 266 ms 5716 KB Output is correct
7 Correct 299 ms 5716 KB Output is correct
8 Correct 203 ms 4436 KB Output is correct
9 Correct 306 ms 5464 KB Output is correct
10 Correct 255 ms 5160 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 463 ms 10816 KB Output is correct
13 Correct 744 ms 4168 KB Output is correct
14 Correct 163 ms 856 KB Output is correct
15 Correct 877 ms 5856 KB Output is correct
16 Correct 102 ms 11264 KB Output is correct
17 Correct 475 ms 7792 KB Output is correct
18 Correct 747 ms 11604 KB Output is correct
19 Correct 650 ms 11860 KB Output is correct
20 Correct 593 ms 11148 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 300 ms 8588 KB Output is correct
13 Correct 198 ms 8784 KB Output is correct
14 Correct 270 ms 5536 KB Output is correct
15 Correct 304 ms 5280 KB Output is correct
16 Correct 204 ms 4436 KB Output is correct
17 Correct 295 ms 5548 KB Output is correct
18 Correct 247 ms 5072 KB Output is correct
19 Correct 481 ms 10944 KB Output is correct
20 Correct 752 ms 4208 KB Output is correct
21 Correct 159 ms 856 KB Output is correct
22 Correct 877 ms 5832 KB Output is correct
23 Correct 105 ms 11348 KB Output is correct
24 Correct 471 ms 7764 KB Output is correct
25 Correct 714 ms 11604 KB Output is correct
26 Correct 644 ms 11688 KB Output is correct
27 Correct 592 ms 11568 KB Output is correct
28 Correct 431 ms 157556 KB Output is correct
29 Correct 1146 ms 175696 KB Output is correct
30 Correct 2727 ms 119640 KB Output is correct
31 Correct 2548 ms 91476 KB Output is correct
32 Correct 301 ms 1104 KB Output is correct
33 Correct 385 ms 2640 KB Output is correct
34 Correct 258 ms 172880 KB Output is correct
35 Correct 815 ms 88040 KB Output is correct
36 Correct 1639 ms 173124 KB Output is correct
37 Correct 1223 ms 173296 KB Output is correct
38 Correct 1210 ms 172884 KB Output is correct
39 Correct 1014 ms 133200 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 317 ms 8632 KB Output is correct
13 Correct 193 ms 8852 KB Output is correct
14 Correct 278 ms 5712 KB Output is correct
15 Correct 307 ms 5456 KB Output is correct
16 Correct 216 ms 4436 KB Output is correct
17 Correct 289 ms 5460 KB Output is correct
18 Correct 248 ms 5060 KB Output is correct
19 Correct 482 ms 10864 KB Output is correct
20 Correct 760 ms 4180 KB Output is correct
21 Correct 165 ms 840 KB Output is correct
22 Correct 876 ms 5852 KB Output is correct
23 Correct 101 ms 11348 KB Output is correct
24 Correct 468 ms 7812 KB Output is correct
25 Correct 717 ms 11516 KB Output is correct
26 Correct 661 ms 11840 KB Output is correct
27 Correct 597 ms 11244 KB Output is correct
28 Correct 437 ms 157524 KB Output is correct
29 Correct 1150 ms 175684 KB Output is correct
30 Correct 2783 ms 119776 KB Output is correct
31 Correct 2608 ms 91484 KB Output is correct
32 Correct 302 ms 1120 KB Output is correct
33 Correct 392 ms 2640 KB Output is correct
34 Correct 258 ms 172844 KB Output is correct
35 Correct 815 ms 87888 KB Output is correct
36 Correct 1561 ms 173136 KB Output is correct
37 Correct 1228 ms 173392 KB Output is correct
38 Correct 1162 ms 172884 KB Output is correct
39 Runtime error 449 ms 256000 KB Execution killed with signal 9
40 Halted 0 ms 0 KB -