답안 #1062833

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1062833 2024-08-17T11:07:14 Z ewirlan 식물 비교 (IOI20_plants) C++17
100 / 100
645 ms 119124 KB
//
#ifndef __SIZEOF_INT128__
    #define __SIZEOF_INT128__
#endif
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
template <typename T> using oset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define rep(i, p, k) for(int i(p); i < (k); ++i)
#define per(i, p, k) for(int i(p); i > (k); --i)
#define sz(x) (int)(x).size()
#define sc static_cast
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef __int128_t lll;
//#define int ll
template <typename T = int> using par = std::pair <T, T>;
#define fi first
#define se second
#define test int _number_of_tests(in()); while(_number_of_tests--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb emplace_back
struct Timer {
    string name{""};
    time_point<high_resolution_clock> end, start{high_resolution_clock::now()};
    duration<float, std::milli> dur;
    Timer() = default;
    Timer(string nm): name(nm) {}
    ~Timer() {
        end = high_resolution_clock::now(); dur= end - start;
        cout << "@" << name << "> " << dur.count() << " ms" << '\n';
    }
};
template <typename T = int> inline T in()
{
    static T x;
    std::cin >> x;
    return x;
}
std::string yn(bool b)
{
    if(b) return "YES\n";
    else return "NO\n";
}
template <typename F, typename S> std::ostream& operator<<(std::ostream& out, const std::pair <F, S>& par);
template <typename T> std::ostream& operator<< (std::ostream& out, const std::vector <T>& wek)
{
    for(const auto& i : wek)out << i << ' ';
    return out;
}
template <typename F, typename S> std::ostream& operator<<(std::ostream& out, const std::pair <F, S>& par)
{
    out << '{'<<par.first<<", "<<par.second<<"}";
    return out;
}
#define show(x) cerr << #x << " = " << x << '\n';
#include "plants.h"
constexpr int maxn = 2e5 + 3, maxk = 20, pol = 1<<18;
int ls[maxn][maxk], rs[maxn][maxk], ko[maxn];
ll ld[maxn][maxk], rd[maxn][maxk];
int n;
constexpr int tres = pol*2+3;
struct t2t{
    int m, g;
};
t2t operator+(t2t a, t2t b){ return (a.m < b.m) ? b : a; }
t2t t2[tres];
t2t t2s(int a, int b){
    t2t o{-1, n};
    a += pol-1; b += pol+1;
    while(a+1 != b){
        if(a % 2 == 0)o = o + t2[a+1];
        if(b % 2 == 1)o = o + t2[b-1];
        a /= 2; b /= 2;
    }
    return o;
}
int tre[tres], tre2[tres];
void upd(int w){
    tre[2*w] += tre2[w];
    tre2[2*w] += tre2[w];
    tre[2*w+1] += tre2[w];
    tre2[2*w+1] += tre2[w];
    tre2[w] = 0;
}
void add(int a, int b, int c, int p = 0, int k = pol-1, int w = 1){
    if(a > k || p > b)return;
    if(a <= p && k <= b){
        tre[w] += c;
        tre2[w] += c;
        return;
    }
    upd(w);
    add(a, b, c, p, (p+k)/2, w*2);
    add(a, b, c, (p+k)/2+1, k, w*2+1);
    tre[w] = min(tre[2*w], tre[2*w+1]);
}
int find(int p = 0, int k = pol-1, int w = 1){
    if(p == k)return p;
    upd(w);
    if(tre[w*2] == 0)return find(p, (p+k)/2, w*2);
    return find((p+k)/2+1, k, w*2+1);
}
set <int> s, t;
int kk;
void supd(int a)
{
    if(sz(s) == 1){
        t.insert(a);
        return;
    }
    t.erase(a);
    auto p(s.find(a));
    if(p == s.begin())p = s.end();
    --p;
    if((a - *p + n)%n >= kk)t.insert(a);
}
void init(int k, vector <int> r)
{
    kk = k;
    n = sz(r);
    rep(i, 0, tres)t2[i] = {-1, n};
    rep(i, 0, pol)tre[i+pol] = (i < n) ? r[i] : 1e9;
    per(i, pol-1, 0)tre[i] = min(tre[2*i], tre[2*i+1]);
    rep(c, 1, n+1){
        while(tre[1] == 0){
            int f(find());
            add(f, f, 1e9);
            s.insert(f);
            supd(f);
            auto p(next(s.find(f)));
            if(p == s.end())p = s.begin();
            if(*p != f)supd(*p);
        } 
        int a(*t.begin());
        t.erase(a);
        s.erase(a);
        auto p(s.lower_bound(a));
        if(p == s.end())p = s.begin();
        if(p != s.end())supd(*p);
        if(a-k+1 < 0){
            add(n+a-k+1, n-1, -1);
            add(0, a-1, -1);
        }
        else add(a-k+1, a-1, -1);
 
        auto [lm, lg] = (a-k+1 >= 0) ? t2s(a-k+1, a-1) : t2s(n+a-k+1, n-1) + t2s(0, a-1);
        ls[a][0] = lg;
        ld[a][0] = lg == n ? -1 : (n+a-lg)%n;
        auto [rm, rg] = (a+k-1 < n) ? t2s(a+1, a+k-1) : t2s(a, n-1) + t2s(0, a+k-1-n);
        rs[a][0] = rg;
        rd[a][0] = rg == n ? -1 : (n+rg-a)%n;
 
        r[a] = -c;
        ko[a] = c;
        int t2g(a+pol);
        t2[t2g] = {ko[a], a};
        while(t2g > 1){
            t2g /= 2;
            t2[t2g] = t2[t2g*2] + t2[t2g*2+1];
        }
    }
    ko[n] = -1;
    ls[n][0] = rs[n][0] = n;
    rep(k, 1, maxk)rep(i, 0, n+1){
        ls[i][k] = ls[ls[i][k-1]][k-1];
        ld[i][k] = ld[i][k-1] + ld[ls[i][k-1]][k-1];
    }
    rep(k, 1, maxk)rep(i, 0, n+1){
        rs[i][k] = rs[rs[i][k-1]][k-1];
        rd[i][k] = rd[i][k-1] + rd[rs[i][k-1]][k-1];
    }
}
int compare_plants(int x, int y)
{
    int m(1);
    if(ko[x] > ko[y]){
        swap(x, y);
        m = -1;
    }
    int z(y);
    ll d(0);
    per(k, maxk-1, -1){
        while(ko[ls[z][k]] >= ko[x]){
            d += ld[z][k];
            z = ls[z][k];
        }
    }
    if(x < y){
        if(y-d <= x)return m;
    }
    else{
        if(y-d <= x-n)return m;
    }
    z = y;
    d = 0;
    per(k, maxk-1, -1){
        while(ko[rs[z][k]] >= ko[x]){
            d += rd[z][k];
            z = rs[z][k];
        }
    }
    if(x < y){
        if(y+d >= x+n)return m;
    }
    else{
        if(y+d >= x)return m;
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 3 ms 6492 KB Output is correct
4 Correct 2 ms 6744 KB Output is correct
5 Correct 3 ms 6492 KB Output is correct
6 Correct 42 ms 10472 KB Output is correct
7 Correct 91 ms 21228 KB Output is correct
8 Correct 344 ms 114768 KB Output is correct
9 Correct 344 ms 114084 KB Output is correct
10 Correct 344 ms 114260 KB Output is correct
11 Correct 391 ms 114772 KB Output is correct
12 Correct 424 ms 114660 KB Output is correct
13 Correct 441 ms 119124 KB Output is correct
14 Correct 347 ms 109648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6492 KB Output is correct
2 Correct 3 ms 6492 KB Output is correct
3 Correct 3 ms 6492 KB Output is correct
4 Correct 4 ms 6492 KB Output is correct
5 Correct 3 ms 6492 KB Output is correct
6 Correct 8 ms 7088 KB Output is correct
7 Correct 69 ms 11860 KB Output is correct
8 Correct 4 ms 6744 KB Output is correct
9 Correct 8 ms 7000 KB Output is correct
10 Correct 73 ms 11716 KB Output is correct
11 Correct 67 ms 11828 KB Output is correct
12 Correct 70 ms 11856 KB Output is correct
13 Correct 70 ms 11860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6492 KB Output is correct
2 Correct 3 ms 6492 KB Output is correct
3 Correct 3 ms 6492 KB Output is correct
4 Correct 4 ms 6492 KB Output is correct
5 Correct 3 ms 6492 KB Output is correct
6 Correct 8 ms 7088 KB Output is correct
7 Correct 69 ms 11860 KB Output is correct
8 Correct 4 ms 6744 KB Output is correct
9 Correct 8 ms 7000 KB Output is correct
10 Correct 73 ms 11716 KB Output is correct
11 Correct 67 ms 11828 KB Output is correct
12 Correct 70 ms 11856 KB Output is correct
13 Correct 70 ms 11860 KB Output is correct
14 Correct 110 ms 19280 KB Output is correct
15 Correct 589 ms 106820 KB Output is correct
16 Correct 113 ms 19284 KB Output is correct
17 Correct 605 ms 106832 KB Output is correct
18 Correct 528 ms 111444 KB Output is correct
19 Correct 443 ms 106576 KB Output is correct
20 Correct 616 ms 106756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6492 KB Output is correct
2 Correct 3 ms 6492 KB Output is correct
3 Correct 57 ms 10276 KB Output is correct
4 Correct 411 ms 109764 KB Output is correct
5 Correct 457 ms 107348 KB Output is correct
6 Correct 497 ms 106836 KB Output is correct
7 Correct 577 ms 106836 KB Output is correct
8 Correct 582 ms 106580 KB Output is correct
9 Correct 428 ms 109128 KB Output is correct
10 Correct 460 ms 107388 KB Output is correct
11 Correct 468 ms 115976 KB Output is correct
12 Correct 402 ms 106576 KB Output is correct
13 Correct 545 ms 113236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6492 KB Output is correct
2 Correct 3 ms 6504 KB Output is correct
3 Correct 3 ms 6492 KB Output is correct
4 Correct 3 ms 6492 KB Output is correct
5 Correct 3 ms 6492 KB Output is correct
6 Correct 4 ms 6748 KB Output is correct
7 Correct 14 ms 7516 KB Output is correct
8 Correct 15 ms 7768 KB Output is correct
9 Correct 19 ms 7768 KB Output is correct
10 Correct 15 ms 7772 KB Output is correct
11 Correct 14 ms 7516 KB Output is correct
12 Correct 14 ms 7772 KB Output is correct
13 Correct 13 ms 7748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6492 KB Output is correct
2 Correct 3 ms 6492 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 4 ms 7000 KB Output is correct
6 Correct 379 ms 106728 KB Output is correct
7 Correct 424 ms 108880 KB Output is correct
8 Correct 521 ms 108960 KB Output is correct
9 Correct 564 ms 109020 KB Output is correct
10 Correct 348 ms 111396 KB Output is correct
11 Correct 483 ms 109592 KB Output is correct
12 Correct 403 ms 111592 KB Output is correct
13 Correct 397 ms 109488 KB Output is correct
14 Correct 431 ms 109140 KB Output is correct
15 Correct 473 ms 109396 KB Output is correct
16 Correct 406 ms 110672 KB Output is correct
17 Correct 399 ms 109116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 3 ms 6492 KB Output is correct
4 Correct 2 ms 6744 KB Output is correct
5 Correct 3 ms 6492 KB Output is correct
6 Correct 42 ms 10472 KB Output is correct
7 Correct 91 ms 21228 KB Output is correct
8 Correct 344 ms 114768 KB Output is correct
9 Correct 344 ms 114084 KB Output is correct
10 Correct 344 ms 114260 KB Output is correct
11 Correct 391 ms 114772 KB Output is correct
12 Correct 424 ms 114660 KB Output is correct
13 Correct 441 ms 119124 KB Output is correct
14 Correct 347 ms 109648 KB Output is correct
15 Correct 3 ms 6492 KB Output is correct
16 Correct 3 ms 6492 KB Output is correct
17 Correct 3 ms 6492 KB Output is correct
18 Correct 4 ms 6492 KB Output is correct
19 Correct 3 ms 6492 KB Output is correct
20 Correct 8 ms 7088 KB Output is correct
21 Correct 69 ms 11860 KB Output is correct
22 Correct 4 ms 6744 KB Output is correct
23 Correct 8 ms 7000 KB Output is correct
24 Correct 73 ms 11716 KB Output is correct
25 Correct 67 ms 11828 KB Output is correct
26 Correct 70 ms 11856 KB Output is correct
27 Correct 70 ms 11860 KB Output is correct
28 Correct 110 ms 19280 KB Output is correct
29 Correct 589 ms 106820 KB Output is correct
30 Correct 113 ms 19284 KB Output is correct
31 Correct 605 ms 106832 KB Output is correct
32 Correct 528 ms 111444 KB Output is correct
33 Correct 443 ms 106576 KB Output is correct
34 Correct 616 ms 106756 KB Output is correct
35 Correct 3 ms 6492 KB Output is correct
36 Correct 3 ms 6492 KB Output is correct
37 Correct 57 ms 10276 KB Output is correct
38 Correct 411 ms 109764 KB Output is correct
39 Correct 457 ms 107348 KB Output is correct
40 Correct 497 ms 106836 KB Output is correct
41 Correct 577 ms 106836 KB Output is correct
42 Correct 582 ms 106580 KB Output is correct
43 Correct 428 ms 109128 KB Output is correct
44 Correct 460 ms 107388 KB Output is correct
45 Correct 468 ms 115976 KB Output is correct
46 Correct 402 ms 106576 KB Output is correct
47 Correct 545 ms 113236 KB Output is correct
48 Correct 3 ms 6492 KB Output is correct
49 Correct 3 ms 6504 KB Output is correct
50 Correct 3 ms 6492 KB Output is correct
51 Correct 3 ms 6492 KB Output is correct
52 Correct 3 ms 6492 KB Output is correct
53 Correct 4 ms 6748 KB Output is correct
54 Correct 14 ms 7516 KB Output is correct
55 Correct 15 ms 7768 KB Output is correct
56 Correct 19 ms 7768 KB Output is correct
57 Correct 15 ms 7772 KB Output is correct
58 Correct 14 ms 7516 KB Output is correct
59 Correct 14 ms 7772 KB Output is correct
60 Correct 13 ms 7748 KB Output is correct
61 Correct 58 ms 12136 KB Output is correct
62 Correct 80 ms 21300 KB Output is correct
63 Correct 373 ms 110928 KB Output is correct
64 Correct 443 ms 109908 KB Output is correct
65 Correct 505 ms 109904 KB Output is correct
66 Correct 590 ms 110164 KB Output is correct
67 Correct 645 ms 110404 KB Output is correct
68 Correct 531 ms 112084 KB Output is correct
69 Correct 586 ms 110944 KB Output is correct
70 Correct 510 ms 112724 KB Output is correct
71 Correct 543 ms 110448 KB Output is correct
72 Correct 613 ms 110176 KB Output is correct
73 Correct 612 ms 110300 KB Output is correct
74 Correct 418 ms 110676 KB Output is correct
75 Correct 494 ms 109920 KB Output is correct