이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/////////////////////include/////////////////////
//#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cassert>
#include <set>
#include <map>
#include <unordered_map>
#include <vector>
#include <stack>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stdio.h>
#include <climits>
#include <numeric>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/////////////////////define/////////////////////
#define ci(x) if(x) cout << "YES" << endl; else cout << "NO" << endl;
#define cii(x) if(check(x))
#define MOD 1000000007
#define MOD2 998244353
#define oo 1e9
#define ool 1e18L
#define pii pair<int, int>
#define pll pair<long long, long long>
#define mii map<int, int>
#define vi vector<int>
#define vpi vector<pair<int, int>>
#define vll vector <ll>
#define ff first
#define ss second
#define mp make_pair
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define sz(x) (int((x).size()))
#define all(x) (x).begin(), (x).end()
#define alll(x) (x), (x) + n
#define clr(x) (x).clear();
#define fri(x) for(int i = 0; i < x; ++i)
#define frj(x) for(int j = 0; j < x; ++j)
#define frr(a, b) for(int i = a; i < b; ++i)
#define frrj(a, b) for(int j = a; j < b; ++j)
#define fra(x) for(int i = 0; i < x; ++i) cin >> a[i];
#define frb(x) for(int i = 0; i < x; ++i) cin >> b[i];
#define frs(x) for(auto it = x.begin(); it != x.end(); ++it)
#define fr(x) for(auto it : x) //el
#define fastio ios_base::sync_with_stdio(false); cin.tie(0);
#define dbg(x) cerr << #x << ": " << x << endl;
#define ce(x) cout << x << endl;
#define uniq(x) x.resize(unique(all(x)) - x.begin()); //make all one after sorting
#define blt __builtin_popcount
/////////////////////print array, vector, deque, set, multiset, pair, map /////////////////////
void print(long long t) {cerr << t;}
void print(int t) {cerr << t;}
void print(string t) {cerr << t;}
void print(char t) {cerr << t;}
void print(double t) {cerr << t;}
void print(long double t) {cerr << t;}
void print(unsigned long long t) {cerr << t;}
template <class T, class V> void print(T v[],V n) {cerr << "["; for(int i = 0; i < n; i++) {print(v[i]); cerr << " "; } cerr << "]"; cout << endl;}
template <class T, class V> void print(pair <T, V> p) {cerr << "{"; print(p.first); cerr << ","; print(p.second); cerr << "}";}
template <class T> void print(vector <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]"; cout << endl;}
template <class T> void print(set <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]"; cout << endl;}
template <class T> void print(multiset <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]"; cout << endl;}
template <class T> void print(stack <T> v) {cerr << "[ "; stack<T> s = v; while(s.size()) {int i = s.top(); print(i); s.pop(); cerr << " ";} cerr << "]"; cout << endl;}
template <class T> void print(queue <T> v) {cerr << "[ "; queue<T> s = v; while(s.size()) {int i = s.front(); print(i); s.pop(); cerr << " ";} cerr << "]"; cout << endl;}
template <class T> void print(deque <T> v) {cerr << "[ "; deque<T> s = v; while(s.size()) {int i = s.front(); print(i); s.pop_front(); cerr << " ";} cerr << "]"; cout << endl;}
template <class T, class V> void print(map <T, V> v) {cerr << "[ "; for (auto i : v) {print(i); cerr << " ";} cerr << "]"; cout << endl;}
template <class T, class V> void print(unordered_map <T, V> v) {cerr << "[ "; for (auto i : v) {print(i); cerr << " ";} cerr << "]"; cout << endl;}
/////////////////////code/////////////////////
vector<pair<long long, long long>> segments[2], newseg[2];
long long k, blockcnt, blocksize;
vll l_[2][5005], r_[2][5005];
pll a[400005];
bool good(pll& a, pll& b) {
return ((min(a.ss, b.ss) - max(a.ff, b.ff) + 1) >= k);
}
bool cmp(pll &a, pll &b) {
return (a.ss - a.ff < b.ss - b.ff);
}
void build(long long id) {
for(pll p : newseg[id])
segments[id].pb(p);
newseg[id].clear();
for(int i = 0; i < blocksize; i++) {
l_[id][i].clear();
r_[id][i].clear();
}
long long n = segments[id].size();
sort(all(segments[id]), cmp);
for(int i = 0; i < segments[id].size(); i++) {
l_[id][i / blockcnt].push_back(segments[id][i].first);
r_[id][i / blockcnt].push_back(segments[id][i].second);
}
for(int i = 0; i < blocksize; i++) {
sort(all(l_[id][i]));
sort(all(r_[id][i]));
}
}
long long getans(long long l, long long r, long long id) {
long long ans = 0;
pll curr_segment = {l, r};
for(int i = 0, curr_block = 0; i < sz(segments[id]); i += blocksize, curr_block++) {
int st = i, en = min((long long)sz(segments[id]) - 1, i + blocksize - 1);
if((segments[id][st].second - segments[id][st].first + 1) >= k) {
ans += en - st + 1;
ans -= sz(l_[id][curr_block]) - (lower_bound(all(l_[id][curr_block]), r - k + 2) - l_[id][curr_block].begin());
ans -= (upper_bound(all(r_[id][curr_block]), l + k - 2) - r_[id][curr_block].begin());
} else if((segments[id][en].second - segments[id][en].first + 1) >= k) {
for(int j = st + 1; j <= en; j++) {
if(good(segments[id][j], curr_segment)) {
ans++;
}
}
}
}
return ans;
}
int main() {
fastio;
long long q, t, tp, l, r, lastans = 0, id = 1, ind;
cin >> q >> t;
blockcnt = blocksize = 555;
while(q--) {
cin >> tp;
if(tp == 1) {
cin >> l >> r;
l = l ^ (t * lastans);
r = r ^ (t * lastans);
if(l > r) swap(l, r);
a[id] = {l, r}; id++;
newseg[0].eb(l, r);
if(newseg[0].size() >= blocksize)
build(0);
}
else if(tp == 2) {
cin >> ind;
l = a[ind].ff; r = a[ind].ss;
newseg[1].eb(l, r);
if(newseg[1].size() >= blocksize)
build(1);
}
else {
cin >> l >> r >> k;
l = l ^ (t * lastans);
r = r ^ (t * lastans);
if(l > r) swap(l, r);
long long ans = 0;
if(r - l + 1 >= k) {
pll p1 = {l, r};
ans = getans(l, r, 0) - getans(l, r, 1);
for(pll p : newseg[0])
if(good(p1, p)) ans++;
for(pll p : newseg[1])
if(good(p1, p)) ans--;
}
cout << ans << "\n";
lastans = ans;
}
}
return 0;
}
// ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥
// ♥ ♥ ♥ ♥ ♥ ♥ ♥
// ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥
// ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥
// ♥ ♥ ♥ ♥ ♥ ♥ ♥ ♥
//
// God loves Fil, Fil accepts God's will
컴파일 시 표준 에러 (stderr) 메시지
segments.cpp: In function 'void build(long long int)':
segments.cpp:113:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
113 | for(int i = 0; i < segments[id].size(); i++) {
| ~~^~~~~~~~~~~~~~~~~~~~~
segments.cpp:110:15: warning: unused variable 'n' [-Wunused-variable]
110 | long long n = segments[id].size();
| ^
segments.cpp: In function 'int main()':
segments.cpp:162:33: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
162 | if(newseg[0].size() >= blocksize)
| ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
segments.cpp:169:33: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
169 | if(newseg[1].size() >= blocksize)
| ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |