Submission #1021672

# Submission time Handle Problem Language Result Execution time Memory
1021672 2024-07-13T02:19:49 Z Dukey Monkey and Apple-trees (IZhO12_apple) C++17
Compilation error
0 ms 0 KB
// Thanks to : TVA
// Strycks, L3, PAD, TVT, NGUYEN^2, Whisper
// My friends...
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pii pair<int, int>
#define plli pair<ll, int>
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define bit(mask, i) ((mask >> i) & 1)
#define fi first
#define se second
#define For(i, a, b) for(int i = (a) ; i <= (b) ; ++i)
#define Ford(i, b, a) for(int i = (b) ; i >= (a) ; --i)
#define FILE freopen(name".INP", "r", stdin); freopen(name".OUT", "w", stdout);

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using str = string;
using ld = long double;
using ull = unsigned long long;
using htype = unsigned long long;

template <class T> bool ckmin(T &a, const T &b) {return (a > b ? a = b, true : false); };
template <class T> bool ckmax(T &a, const T &b) {return (a < b ? a = b, true : false); };
template <class T> void compress(vector <T> &a) {sort(all(a)); a.resize(unique(all(a)) - a.begin()); };
template <class T> int getcom(vector<T> &a, T val) {return lower_bound(all(a), val) - a.begin() + 1; };

const ll mod = 1e9 + 7;                             /// MOD CHANGED

ll add(ll x, ll y){
    return (x + y) % mod;
}

ll sub(ll x, ll y){
    return ((x - y) % mod + mod) % mod;
}

ll mul(ll x, ll y){
    return (x * y) % mod;
}

mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());

const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
const char MOVE[] = {'U', 'L', 'R', 'D'};

const ll INFll = 0x3f3f3f3f3f3f3f3f;
const int INFin = 0x3f3f3f3f;

const int maxn = 123456;                           /// MAXN CHANGED

const int maxv = 1e6 + 5;                         /// MAXV CHANGED

struct node{
    int sum, lazy, tl, tr, l, r;
    node() : sum(0), lazy(0), l(-1), r(-1) {};
};

node it[64 * maxn];
int cnt = 2;

void push(int node){
    if(it[node].lazy){
        it[node].sum = it[node].tr - it[node].tl + 1;
        int mid = (it[node].tl + it[node].tr) >> 1;
        if(it[node].l == -1){
            it[node].l = cnt++;
            it[it[node].l].tl = it[node].tl;
            it[it[node].l].tr = mid;
        }
        if(it[node].r == -1){
            it[node].r = cnt++;
            it[it[node].r].tl = mid + 1;
            it[it[node].r].tr = it[node].tr;
        }
        it[it[node].l].lazy = it[it[node].r].lazy = 1;
        it[node].lazy = 0;
    }
}

void upd(int node, int l, int r){
    push(node);
    if(l == it[node].tl && r == it[node].tr){
        it[node].lazy = 1;
        push(node);
    }
    else{
        int mid = (it[node].tl + it[node].tr) >> 1;
        if(it[node].l == -1){
            it[node].l = cnt++;
            it[it[node].l].tl = it[node].tl;
            it[it[node].l].tr = mid;
        }
        if(it[node].r == -1){
            it[node].r = cnt++;
            it[it[node].r].tl = mid + 1;
            it[it[node].r].tr = it[node].tr;
        }
        if(l > mid) upd(it[node].r, l, r);
        else if(r <= mid) upd(it[node].l, l, r);
        else{
            upd(it[node].l, l, mid);
            upd(it[node].r, mid + 1, r);
        }

        push(it[node].l);
        push(it[node].r);

        it[node].sum = it[it[node].l].sum + it[it[node].r].sum;
    }
}

int query(int node, int l, int r){
    push(node);
    if(l == it[node].tl && r == it[node].tr) return it[node].sum;
    int mid = (it[node].tl + it[node].tr) >> 1;

    if(it[node].l == -1){
        it[node].l = cnt++;
        it[it[node].l].tl = it[node].tl;
        it[it[node].l].tr = mid;
    }   
    if(it[node].r == -1){
        it[node].r = cnt++;
        it[it[node].r].tl = mid + 1;
        it[it[node].r].tr = it[node].tr;
    }

    if(l > mid) return query(it[node].r, l, r);
    else if(r <= mid) return query(it[node].l, l, r);
    else return query(it[node].l, l, mid) + query(it[node].r, mid + 1, r);
}

int main(){
    fast
    #define name "Anya"
    // FILE
    int m; cin >> m;

    it[1].sum = 0;
    it[1].lazy = 0;
    it[1].tl = 1;
    it[1].tr = 1e9;

    int c = 0;
    For(i, 1, m){
        int d, x, y; cin >> d >> x >> y;
        if(d == 1){
            c = query(1, x + c, y + c);
            cout << c << '\n';
        }else upd(1, x + c, y + c);
    }
}// Thanks to : TVA
// Strycks, L3, PAD, TVT, NGUYEN^2, Whisper
// My friends...
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pii pair<int, int>
#define plli pair<ll, int>
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define bit(mask, i) ((mask >> i) & 1)
#define fi first
#define se second
#define For(i, a, b) for(int i = (a) ; i <= (b) ; ++i)
#define Ford(i, b, a) for(int i = (b) ; i >= (a) ; --i)
#define FILE freopen(name".INP", "r", stdin); freopen(name".OUT", "w", stdout);

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using str = string;
using ld = long double;
using ull = unsigned long long;
using htype = unsigned long long;

template <class T> bool ckmin(T &a, const T &b) {return (a > b ? a = b, true : false); };
template <class T> bool ckmax(T &a, const T &b) {return (a < b ? a = b, true : false); };
template <class T> void compress(vector <T> &a) {sort(all(a)); a.resize(unique(all(a)) - a.begin()); };
template <class T> int getcom(vector<T> &a, T val) {return lower_bound(all(a), val) - a.begin() + 1; };

const ll mod = 1e9 + 7;                             /// MOD CHANGED

ll add(ll x, ll y){
    return (x + y) % mod;
}

ll sub(ll x, ll y){
    return ((x - y) % mod + mod) % mod;
}

ll mul(ll x, ll y){
    return (x * y) % mod;
}

mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());

const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
const char MOVE[] = {'U', 'L', 'R', 'D'};

const ll INFll = 0x3f3f3f3f3f3f3f3f;
const int INFin = 0x3f3f3f3f;

const int maxn = 123456;                           /// MAXN CHANGED

const int maxv = 1e6 + 5;                         /// MAXV CHANGED

struct node{
    int sum, lazy, tl, tr, l, r;
    node() : sum(0), lazy(0), l(-1), r(-1) {};
};

node it[64 * maxn];
int cnt = 2;

void push(int node){
    if(it[node].lazy){
        it[node].sum = it[node].tr - it[node].tl + 1;
        int mid = (it[node].tl + it[node].tr) >> 1;
        if(it[node].l == -1){
            it[node].l = cnt++;
            it[it[node].l].tl = it[node].tl;
            it[it[node].l].tr = mid;
        }
        if(it[node].r == -1){
            it[node].r = cnt++;
            it[it[node].r].tl = mid + 1;
            it[it[node].r].tr = it[node].tr;
        }
        it[it[node].l].lazy = it[it[node].r].lazy = 1;
        it[node].lazy = 0;
    }
}

void upd(int node, int l, int r){
    push(node);
    if(l == it[node].tl && r == it[node].tr){
        it[node].lazy = 1;
        push(node);
    }
    else{
        int mid = (it[node].tl + it[node].tr) >> 1;
        if(it[node].l == -1){
            it[node].l = cnt++;
            it[it[node].l].tl = it[node].tl;
            it[it[node].l].tr = mid;
        }
        if(it[node].r == -1){
            it[node].r = cnt++;
            it[it[node].r].tl = mid + 1;
            it[it[node].r].tr = it[node].tr;
        }
        if(l > mid) upd(it[node].r, l, r);
        else if(r <= mid) upd(it[node].l, l, r);
        else{
            upd(it[node].l, l, mid);
            upd(it[node].r, mid + 1, r);
        }

        push(it[node].l);
        push(it[node].r);

        it[node].sum = it[it[node].l].sum + it[it[node].r].sum;
    }
}

int query(int node, int l, int r){
    push(node);
    if(l == it[node].tl && r == it[node].tr) return it[node].sum;
    int mid = (it[node].tl + it[node].tr) >> 1;

    if(it[node].l == -1){
        it[node].l = cnt++;
        it[it[node].l].tl = it[node].tl;
        it[it[node].l].tr = mid;
    }   
    if(it[node].r == -1){
        it[node].r = cnt++;
        it[it[node].r].tl = mid + 1;
        it[it[node].r].tr = it[node].tr;
    }

    if(l > mid) return query(it[node].r, l, r);
    else if(r <= mid) return query(it[node].l, l, r);
    else return query(it[node].l, l, mid) + query(it[node].r, mid + 1, r);
}

int main(){
    fast
    #define name "Anya"
    // FILE
    int m; cin >> m;

    it[1].sum = 0;
    it[1].lazy = 0;
    it[1].tl = 1;
    it[1].tr = 1e9;

    int c = 0;
    For(i, 1, m){
        int d, x, y; cin >> d >> x >> y;
        if(d == 1){
            c = query(1, x + c, y + c);
            cout << c << '\n';
        }else upd(1, x + c, y + c);
    }
}

Compilation message

apple.cpp:188:25: error: redefinition of 'template<class T> bool ckmin(T&, const T&)'
  188 | template <class T> bool ckmin(T &a, const T &b) {return (a > b ? a = b, true : false); };
      |                         ^~~~~
apple.cpp:29:25: note: 'template<class T> bool ckmin(T&, const T&)' previously declared here
   29 | template <class T> bool ckmin(T &a, const T &b) {return (a > b ? a = b, true : false); };
      |                         ^~~~~
apple.cpp:189:25: error: redefinition of 'template<class T> bool ckmax(T&, const T&)'
  189 | template <class T> bool ckmax(T &a, const T &b) {return (a < b ? a = b, true : false); };
      |                         ^~~~~
apple.cpp:30:25: note: 'template<class T> bool ckmax(T&, const T&)' previously declared here
   30 | template <class T> bool ckmax(T &a, const T &b) {return (a < b ? a = b, true : false); };
      |                         ^~~~~
apple.cpp:190:25: error: redefinition of 'template<class T> void compress(std::vector<_Tp>&)'
  190 | template <class T> void compress(vector <T> &a) {sort(all(a)); a.resize(unique(all(a)) - a.begin()); };
      |                         ^~~~~~~~
apple.cpp:31:25: note: 'template<class T> void compress(std::vector<_Tp>&)' previously declared here
   31 | template <class T> void compress(vector <T> &a) {sort(all(a)); a.resize(unique(all(a)) - a.begin()); };
      |                         ^~~~~~~~
apple.cpp:191:24: error: redefinition of 'template<class T> int getcom(std::vector<_Tp>&, T)'
  191 | template <class T> int getcom(vector<T> &a, T val) {return lower_bound(all(a), val) - a.begin() + 1; };
      |                        ^~~~~~
apple.cpp:32:24: note: 'template<class T> int getcom(std::vector<_Tp>&, T)' previously declared here
   32 | template <class T> int getcom(vector<T> &a, T val) {return lower_bound(all(a), val) - a.begin() + 1; };
      |                        ^~~~~~
apple.cpp:193:10: error: redefinition of 'const ll mod'
  193 | const ll mod = 1e9 + 7;                             /// MOD CHANGED
      |          ^~~
apple.cpp:34:10: note: 'const ll mod' previously defined here
   34 | const ll mod = 1e9 + 7;                             /// MOD CHANGED
      |          ^~~
apple.cpp:195:4: error: redefinition of 'll add(ll, ll)'
  195 | ll add(ll x, ll y){
      |    ^~~
apple.cpp:36:4: note: 'll add(ll, ll)' previously defined here
   36 | ll add(ll x, ll y){
      |    ^~~
apple.cpp:199:4: error: redefinition of 'll sub(ll, ll)'
  199 | ll sub(ll x, ll y){
      |    ^~~
apple.cpp:40:4: note: 'll sub(ll, ll)' previously defined here
   40 | ll sub(ll x, ll y){
      |    ^~~
apple.cpp:203:4: error: redefinition of 'll mul(ll, ll)'
  203 | ll mul(ll x, ll y){
      |    ^~~
apple.cpp:44:4: note: 'll mul(ll, ll)' previously defined here
   44 | ll mul(ll x, ll y){
      |    ^~~
apple.cpp:207:12: error: redefinition of 'std::mt19937_64 rd'
  207 | mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
      |            ^~
apple.cpp:48:12: note: 'std::mt19937_64 rd' previously declared here
   48 | mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
      |            ^~
apple.cpp:209:11: error: redefinition of 'const int dx []'
  209 | const int dx[] = {-1, 0, 0, 1};
      |           ^~
apple.cpp:50:11: note: 'const int dx [4]' previously defined here
   50 | const int dx[] = {-1, 0, 0, 1};
      |           ^~
apple.cpp:210:11: error: redefinition of 'const int dy []'
  210 | const int dy[] = {0, -1, 1, 0};
      |           ^~
apple.cpp:51:11: note: 'const int dy [4]' previously defined here
   51 | const int dy[] = {0, -1, 1, 0};
      |           ^~
apple.cpp:211:12: error: redefinition of 'const char MOVE []'
  211 | const char MOVE[] = {'U', 'L', 'R', 'D'};
      |            ^~~~
apple.cpp:52:12: note: 'const char MOVE [4]' previously defined here
   52 | const char MOVE[] = {'U', 'L', 'R', 'D'};
      |            ^~~~
apple.cpp:213:10: error: redefinition of 'const ll INFll'
  213 | const ll INFll = 0x3f3f3f3f3f3f3f3f;
      |          ^~~~~
apple.cpp:54:10: note: 'const ll INFll' previously defined here
   54 | const ll INFll = 0x3f3f3f3f3f3f3f3f;
      |          ^~~~~
apple.cpp:214:11: error: redefinition of 'const int INFin'
  214 | const int INFin = 0x3f3f3f3f;
      |           ^~~~~
apple.cpp:55:11: note: 'const int INFin' previously defined here
   55 | const int INFin = 0x3f3f3f3f;
      |           ^~~~~
apple.cpp:216:11: error: redefinition of 'const int maxn'
  216 | const int maxn = 123456;                           /// MAXN CHANGED
      |           ^~~~
apple.cpp:57:11: note: 'const int maxn' previously defined here
   57 | const int maxn = 123456;                           /// MAXN CHANGED
      |           ^~~~
apple.cpp:218:11: error: redefinition of 'const int maxv'
  218 | const int maxv = 1e6 + 5;                         /// MAXV CHANGED
      |           ^~~~
apple.cpp:59:11: note: 'const int maxv' previously defined here
   59 | const int maxv = 1e6 + 5;                         /// MAXV CHANGED
      |           ^~~~
apple.cpp:220:8: error: redefinition of 'struct node'
  220 | struct node{
      |        ^~~~
apple.cpp:61:8: note: previous definition of 'struct node'
   61 | struct node{
      |        ^~~~
apple.cpp:225:6: error: redefinition of 'node it [7901184]'
  225 | node it[64 * maxn];
      |      ^~
apple.cpp:66:6: note: 'node it [7901184]' previously declared here
   66 | node it[64 * maxn];
      |      ^~
apple.cpp:226:5: error: redefinition of 'int cnt'
  226 | int cnt = 2;
      |     ^~~
apple.cpp:67:5: note: 'int cnt' previously defined here
   67 | int cnt = 2;
      |     ^~~
apple.cpp:228:6: error: redefinition of 'void push(int)'
  228 | void push(int node){
      |      ^~~~
apple.cpp:69:6: note: 'void push(int)' previously defined here
   69 | void push(int node){
      |      ^~~~
apple.cpp:247:6: error: redefinition of 'void upd(int, int, int)'
  247 | void upd(int node, int l, int r){
      |      ^~~
apple.cpp:88:6: note: 'void upd(int, int, int)' previously defined here
   88 | void upd(int node, int l, int r){
      |      ^~~
apple.cpp:279:5: error: redefinition of 'int query(int, int, int)'
  279 | int query(int node, int l, int r){
      |     ^~~~~
apple.cpp:120:5: note: 'int query(int, int, int)' previously defined here
  120 | int query(int node, int l, int r){
      |     ^~~~~
apple.cpp:300:5: error: redefinition of 'int main()'
  300 | int main(){
      |     ^~~~
apple.cpp:141:5: note: 'int main()' previously defined here
  141 | int main(){
      |     ^~~~