답안 #281794

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
281794 2020-08-23T13:28:00 Z Kastanda 게임 (IOI13_game) C++11
80 / 100
3407 ms 40364 KB
// M
#include<bits/stdc++.h>
#include "game.h"
#define lc (id << 1)
#define rc (lc ^ 1)
#define md ((l + r) >> 1)
using namespace std;
typedef long long ll;
const int N = 22005, TF = 800, MXS = N * 4, NS = N * 15;
int n, m, k, segk;
map < pair < int , int > , ll > MP, TMp;
vector < pair < int , int > > V[N], VC[MXS];
vector < int > UX, VID[MXS];
ll G[NS * 2];
inline void ModifySeg(int i, ll val)
{
        G[i += NS] = val;
        for (; i; i >>= 1)
                G[i >> 1] = __gcd(G[i], G[i ^ 1]);
}
inline ll GetSeg(int l, int r)
{
        ll g = 0;
        for (l += NS, r += NS; l < r; l >>= 1, r >>= 1)
        {
                if (l & 1) g = __gcd(g, G[l ++]);
                if (r & 1) g = __gcd(g, G[-- r]);
        }
        return g;
}
void Build(int id = 1, int l = 0, int r = k)
{
        VC[id].clear();
        VID[id].clear();
        if (r - l < 2)
                sort(V[l].begin(), V[l].end()), VC[id] = V[l];
        else
        {
                Build(lc, l, md);
                Build(rc, md, r);
                merge(VC[lc].begin(), VC[lc].end(), VC[rc].begin(), VC[rc].end(), back_inserter(VC[id]));
        }
        for (int i = 0; i < (int)VC[id].size(); i ++)
        {
                ModifySeg(segk, MP[make_pair(VC[id][i].second, VC[id][i].first)]);
                VID[id].push_back(segk ++);
        }
}
inline void Relax()
{
        segk = 0;
        memset(G, 0, sizeof(G));
        UX.clear();
        for (auto X : TMp)
                MP[X.first] = X.second;
        TMp.clear();

        for (auto e : MP)
                UX.push_back(e.first.first);
        UX.resize(unique(UX.begin(), UX.end()) - UX.begin());
        k = (int)UX.size();
        for (int i = 0; i <= k; i ++)
                V[i].clear();

        int ptr = 0;
        for (auto e : MP)
        {
                while (UX[ptr] < e.first.first)
                        ptr ++;
                V[ptr].push_back(make_pair(e.first.second, e.first.first));
        }
        Build();
        assert(segk < NS);
}
void Update(int i, int c, ll val, int id = 1, int l = 0, int r = k)
{
        int lb = (int)(lower_bound(VC[id].begin(), VC[id].end(), make_pair(c, UX[i])) - VC[id].begin());
        ModifySeg(VID[id][lb], val);
        if (r - l < 2)
                return ;
        if (i < md)
                Update(i, c, val, lc, l, md);
        else
                Update(i, c, val, rc, md, r);
}
void init(int _n, int _m)
{
        n = _n; m = _m;
        Relax();
}
void update(int r, int c, ll val)
{
        if (MP.count({r, c}))
        {
                r = lower_bound(UX.begin(), UX.end(), r) - UX.begin();
                Update(r, c, val);
                MP[make_pair(UX[r], c)] = val;
        }
        else
        {
                TMp[make_pair(r, c)] = val;
                if ((int)TMp.size() >= TF)
                        Relax();
        }
}
ll Get(int le, int ri, int lq, int rq, int id = 1, int l = 0, int r = k)
{
        if (ri <= l || r <= le)
                return 0LL;
        if (le <= l && r <= ri)
        {
                int lb = (int)(lower_bound(VC[id].begin(), VC[id].end(), make_pair(lq, -1)) - VC[id].begin());
                int ub = (int)(lower_bound(VC[id].begin(), VC[id].end(), make_pair(rq, -1)) - VC[id].begin());
                if (lb < ub)
                        return GetSeg(VID[id][lb], VID[id][ub - 1] + 1);
                return 0;
        }
        return __gcd(Get(le, ri, lq, rq, lc, l, md), Get(le, ri, lq, rq, rc, md, r));
}
inline ll Query(int a, int b, int c, int d)
{
        c ++; d ++;
        a = lower_bound(UX.begin(), UX.end(), a) - UX.begin();
        c = lower_bound(UX.begin(), UX.end(), c) - UX.begin();
        return Get(a, c, b, d);
}
ll calculate(int a, int b, int c, int d)
{
        ll g = Query(a, b, c, d);
        for (auto e : TMp)
                if (e.first.first >= a && e.first.first <= c && e.first.second >= b && e.first.second <= d)
                        g = __gcd(g, e.second);
        return g;
}

Compilation message

grader.c: In function 'int main()':
grader.c:18:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
   18 |  int res;
      |      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 10108 KB Output is correct
2 Correct 6 ms 10112 KB Output is correct
3 Correct 6 ms 10112 KB Output is correct
4 Correct 6 ms 10112 KB Output is correct
5 Correct 6 ms 10112 KB Output is correct
6 Correct 7 ms 10112 KB Output is correct
7 Correct 6 ms 10112 KB Output is correct
8 Correct 6 ms 10112 KB Output is correct
9 Correct 6 ms 10112 KB Output is correct
10 Correct 7 ms 10148 KB Output is correct
11 Correct 7 ms 10112 KB Output is correct
12 Correct 7 ms 10112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 10112 KB Output is correct
2 Correct 6 ms 10112 KB Output is correct
3 Correct 6 ms 10112 KB Output is correct
4 Correct 1828 ms 16748 KB Output is correct
5 Correct 1530 ms 17344 KB Output is correct
6 Correct 1593 ms 14712 KB Output is correct
7 Correct 1366 ms 14072 KB Output is correct
8 Correct 1279 ms 14248 KB Output is correct
9 Correct 1409 ms 14356 KB Output is correct
10 Correct 1371 ms 13804 KB Output is correct
11 Correct 7 ms 10112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 10112 KB Output is correct
2 Correct 7 ms 10112 KB Output is correct
3 Correct 6 ms 10112 KB Output is correct
4 Correct 6 ms 10112 KB Output is correct
5 Correct 6 ms 10112 KB Output is correct
6 Correct 7 ms 10112 KB Output is correct
7 Correct 7 ms 10112 KB Output is correct
8 Correct 7 ms 10112 KB Output is correct
9 Correct 7 ms 10112 KB Output is correct
10 Correct 7 ms 10112 KB Output is correct
11 Correct 7 ms 10112 KB Output is correct
12 Correct 2374 ms 19000 KB Output is correct
13 Correct 3337 ms 14328 KB Output is correct
14 Correct 1164 ms 12508 KB Output is correct
15 Correct 3225 ms 14752 KB Output is correct
16 Correct 2565 ms 15736 KB Output is correct
17 Correct 1683 ms 14496 KB Output is correct
18 Correct 2374 ms 15992 KB Output is correct
19 Correct 2212 ms 16120 KB Output is correct
20 Correct 2150 ms 15556 KB Output is correct
21 Correct 7 ms 10112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 10112 KB Output is correct
2 Correct 7 ms 10112 KB Output is correct
3 Correct 7 ms 10112 KB Output is correct
4 Correct 7 ms 10112 KB Output is correct
5 Correct 6 ms 10112 KB Output is correct
6 Correct 6 ms 10112 KB Output is correct
7 Correct 7 ms 10112 KB Output is correct
8 Correct 6 ms 10112 KB Output is correct
9 Correct 7 ms 10112 KB Output is correct
10 Correct 7 ms 10112 KB Output is correct
11 Correct 6 ms 10112 KB Output is correct
12 Correct 1823 ms 16844 KB Output is correct
13 Correct 1581 ms 17276 KB Output is correct
14 Correct 1502 ms 14652 KB Output is correct
15 Correct 1384 ms 14116 KB Output is correct
16 Correct 1279 ms 14072 KB Output is correct
17 Correct 1399 ms 14240 KB Output is correct
18 Correct 1382 ms 13972 KB Output is correct
19 Correct 2260 ms 18628 KB Output is correct
20 Correct 3325 ms 14616 KB Output is correct
21 Correct 1162 ms 12352 KB Output is correct
22 Correct 3233 ms 15184 KB Output is correct
23 Correct 2585 ms 15716 KB Output is correct
24 Correct 1688 ms 14448 KB Output is correct
25 Correct 2369 ms 15992 KB Output is correct
26 Correct 2290 ms 16156 KB Output is correct
27 Correct 2189 ms 15912 KB Output is correct
28 Correct 1617 ms 17272 KB Output is correct
29 Correct 2995 ms 20144 KB Output is correct
30 Correct 3407 ms 16508 KB Output is correct
31 Correct 3048 ms 15480 KB Output is correct
32 Correct 1222 ms 12920 KB Output is correct
33 Correct 2488 ms 13040 KB Output is correct
34 Correct 2726 ms 17272 KB Output is correct
35 Correct 1790 ms 15600 KB Output is correct
36 Correct 2721 ms 17572 KB Output is correct
37 Correct 2545 ms 17696 KB Output is correct
38 Correct 2369 ms 17064 KB Output is correct
39 Correct 2061 ms 16236 KB Output is correct
40 Correct 7 ms 10112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 10112 KB Output is correct
2 Correct 7 ms 10112 KB Output is correct
3 Correct 7 ms 10112 KB Output is correct
4 Correct 6 ms 10112 KB Output is correct
5 Correct 7 ms 10112 KB Output is correct
6 Correct 6 ms 10112 KB Output is correct
7 Correct 7 ms 10112 KB Output is correct
8 Correct 7 ms 10112 KB Output is correct
9 Correct 7 ms 10112 KB Output is correct
10 Correct 7 ms 10112 KB Output is correct
11 Correct 7 ms 10112 KB Output is correct
12 Correct 1870 ms 17276 KB Output is correct
13 Correct 1580 ms 17464 KB Output is correct
14 Correct 1500 ms 14588 KB Output is correct
15 Correct 1489 ms 14252 KB Output is correct
16 Correct 1280 ms 14424 KB Output is correct
17 Correct 1457 ms 14380 KB Output is correct
18 Correct 1487 ms 13944 KB Output is correct
19 Correct 2304 ms 18940 KB Output is correct
20 Correct 3333 ms 14504 KB Output is correct
21 Correct 1181 ms 12608 KB Output is correct
22 Correct 3355 ms 15052 KB Output is correct
23 Correct 2576 ms 15808 KB Output is correct
24 Correct 1703 ms 14564 KB Output is correct
25 Correct 2546 ms 16292 KB Output is correct
26 Correct 2255 ms 16372 KB Output is correct
27 Correct 2146 ms 15492 KB Output is correct
28 Correct 1623 ms 16564 KB Output is correct
29 Correct 2594 ms 19676 KB Output is correct
30 Correct 3394 ms 16140 KB Output is correct
31 Correct 3123 ms 14940 KB Output is correct
32 Correct 1226 ms 11936 KB Output is correct
33 Correct 2427 ms 11488 KB Output is correct
34 Correct 2570 ms 15852 KB Output is correct
35 Correct 1746 ms 14200 KB Output is correct
36 Correct 2734 ms 16164 KB Output is correct
37 Correct 2396 ms 16492 KB Output is correct
38 Correct 2355 ms 15588 KB Output is correct
39 Runtime error 2740 ms 40364 KB Execution killed with signal 11
40 Halted 0 ms 0 KB -