답안 #674084

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
674084 2022-12-22T23:47:18 Z HaccerKat 원숭이와 사과 나무 (IZhO12_apple) C++17
0 / 100
256 ms 153192 KB
#include <bits/stdc++.h>
using namespace std;
template<typename T>
int SIZE(T (&t)){
    return t.size();
}

template<typename T, size_t N>
int SIZE(T (&t)[N]){
    return N;
}

string to_string(char t){
    return "'" + string({t}) + "'";
}

string to_string(bool t){
    return t ? "true" : "false";
}

string to_string(const string &t, int x1=0, int x2=1e9){
    string ret = "";
    for(int i = min(x1,SIZE(t)), _i = min(x2,SIZE(t)-1); i <= _i; ++i){
        ret += t[i];
    }
    return '"' + ret + '"';
}

string to_string(const char* t){
    string ret(t);
    return to_string(ret);
}

template<size_t N>
string to_string(const bitset<N> &t, int x1=0, int x2=1e9){
    string ret = "";
    for(int i = min(x1,SIZE(t)); i <= min(x2,SIZE(t)-1); ++i){
        ret += t[i] + '0';
    }
    return to_string(ret);
}

template<typename T, typename... Coords>
string to_string(const T (&t), int x1=0, int x2=1e9, Coords... C);

template<typename T, typename S>
string to_string(const pair<T, S> &t){
    return "(" + to_string(t.first) + ", " + to_string(t.second) + ")";
}

template<typename T, typename... Coords>
string to_string(const T (&t), int x1, int x2, Coords... C){
    string ret = "[";
    x1 = min(x1, SIZE(t));
    auto e = begin(t);
    advance(e,x1);
    for(int i = x1, _i = min(x2,SIZE(t)-1); i <= _i; ++i){
        ret += to_string(*e, C...) + (i != _i ? ", " : "");
        e = next(e);
    }
    return ret + "]";
}

template<int Index, typename... Ts>
struct print_tuple{
    string operator() (const tuple<Ts...>& t) {
        string ret = print_tuple<Index - 1, Ts...>{}(t);
        ret += (Index ? ", " : "");
        return ret + to_string(get<Index>(t));
    }
};

template<typename... Ts>
struct print_tuple<0, Ts...> {
    string operator() (const tuple<Ts...>& t) {
        return to_string(get<0>(t));
    }
};

template<typename... Ts>
string to_string(const tuple<Ts...>& t) {
    const auto Size = tuple_size<tuple<Ts...>>::value;
    return print_tuple<Size - 1, Ts...>{}(t);
}

void dbgr(){;}
template<typename Heads, typename... Tails>
void dbgr(Heads H, Tails... T){
    cout << to_string(H) << " | ";
    dbgr(T...);
}

void dbgs(){;}
template<typename Heads, typename... Tails>
void dbgs(Heads H, Tails... T){
    cout << H << " ";
    dbgs(T...);
}

/*
formatted functions:
*/

/*
consider __VA_ARGS__ as a whole:
dbgv() prints values only
dbg() prints name and values
*/
#define dbgv(...) cout << to_string(__VA_ARGS__) << endl;

#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgv(__VA_ARGS__);
//#define dbg(...)

/*
consider __VA_ARGS__ as a sequence of arguments:
dbgr() prints values only
dbgm() prints names and values
*/
#define dbgr(...) dbgr(__VA_ARGS__); cout << endl;

#define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgr(__VA_ARGS__);

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;

/*
000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000
                        0000000
                        0000000
                        0000000
                        0000000
                        0000000
                        0000000
                        0000000
                        0000000
                        0000000
                        0000000
                        0000000
                        0000000
                        0000000
                        0000000
                        0000000
                        0000000
                        0000000
                        0000000
                        0000000
                        0000000
DO IT NOW!!!
*/

using u128=__uint128_t;
using i128=__int128;
const int mod=1000000007;
const int N=100005;
const int LOG=30;
const int MX=N*(LOG+2);
const int inf=1e9;
const double eps=1e-11;
string s;
int n, m, k, qq;
struct Node {
	int l, r, cnt, lptr, rptr;
	bool lazy;
	Node() {
		l=0, r=0, cnt=0, lptr=-1, rptr=-1, lazy=false;	
	};
	
	Node(int x, int y) {
		l=x, r=y, cnt=0, lptr=-1, rptr=-1, lazy=false;	
	};
};

Node t[MX];
int cur=1;
void propogate(int v) {
	int mid=(t[v].l+t[v].r)/2;
	if (t[v].lptr==-1) {
		t[v].lptr=cur++;
		t[t[v].lptr]=Node(t[v].l, mid);
	}
	
	if (t[v].rptr==-1) {
		t[v].rptr=cur++;
		t[t[v].rptr]=Node(mid+1, t[v].r);
	}
	
	if (t[v].lazy) {
		t[t[v].lptr].lazy=t[t[v].rptr].lazy=true;
		t[t[v].lptr].cnt=t[t[v].lptr].r-t[t[v].lptr].l+1;
		t[t[v].rptr].cnt=t[t[v].rptr].r-t[t[v].rptr].l+1;
	}
}

void update(int ql, int qr, int v=0) {
	if (ql>t[v].r || qr<t[v].l) return;
	if (ql<=t[v].l && qr>=t[v].r) {
		t[v].cnt=t[v].r-t[v].l+1, t[v].lazy=true;
		return;
	}
	
	propogate(v);
	int mid=(t[v].l+t[v].r)/2;
	update(ql, qr, t[v].lptr);
	update(ql, qr, t[v].rptr);
	t[v].cnt=t[t[v].lptr].cnt+t[t[v].rptr].cnt;
}

int query(int ql, int qr, int v=0) {
	if (ql>t[v].r || qr<t[v].l) return 0;
	if (ql<=t[v].l && qr>=t[v].r) {
		return t[v].cnt;
	}
	
	propogate(v);
	int mid=(t[v].l+t[v].r)/2;
	return query(ql, qr, t[v].lptr)+query(ql, qr, t[v].rptr);
}

void solve() {
    cin>>n;
    int C=0;
    t[0].l=0, t[0].r=(1<<LOG)-1;
    for (int i=0; i<n; i++) {
    	int d, x, y;
    	cin>>d>>x>>y;
    	if (d==1) {
    		C=query(x+C, y+C);
    		cout<<C<<"\n";
    	}
    	
    	else {
    		update(x+C, y+C);
    	}
    }
	
/*
000000000000                                     000000000000
000000000000                                     000000000000
000000000000                                     000000000000
000000000000                                     000000000000
000000000000                                     000000000000
000000000000                                     000000000000
000000000000                                     000000000000
000000000000                                     000000000000
000000000000                                     000000000000
000000000000                                     000000000000
000000000000                                     000000000000
000000000000                                     000000000000
000000000000                                     000000000000
000000000000                                     000000000000
000000000000                                     000000000000
000000000000                                     000000000000
000000000000000000000000000000000000000000000    000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000    000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000    000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000    000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000    000000000000000000000000000000000000000000000
*/

}

int32_t main() {
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}

Compilation message

apple.cpp: In function 'void update(int, int, int)':
apple.cpp:222:6: warning: unused variable 'mid' [-Wunused-variable]
  222 |  int mid=(t[v].l+t[v].r)/2;
      |      ^~~
apple.cpp: In function 'int query(int, int, int)':
apple.cpp:235:6: warning: unused variable 'mid' [-Wunused-variable]
  235 |  int mid=(t[v].l+t[v].r)/2;
      |      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 75456 KB Output is correct
2 Correct 32 ms 75372 KB Output is correct
3 Correct 33 ms 75364 KB Output is correct
4 Correct 43 ms 75476 KB Output is correct
5 Correct 52 ms 75468 KB Output is correct
6 Correct 48 ms 75468 KB Output is correct
7 Correct 47 ms 75424 KB Output is correct
8 Correct 110 ms 75640 KB Output is correct
9 Correct 202 ms 75768 KB Output is correct
10 Correct 203 ms 75832 KB Output is correct
11 Correct 204 ms 75748 KB Output is correct
12 Correct 212 ms 75980 KB Output is correct
13 Correct 206 ms 75852 KB Output is correct
14 Correct 203 ms 75856 KB Output is correct
15 Runtime error 256 ms 153192 KB Execution killed with signal 11
16 Halted 0 ms 0 KB -