이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
Codeforces: Tiananmen89, (1877)
Date: ///////
Generated by github.com/xalanq/cf-tool
*/
#define what_happened_on_tiananmen_square_in_1989 NULL
#include <bits/stdc++.h>
using namespace std;
int exctime = 0;
__attribute__((constructor)) void before_main() {
cin.tie(0)->sync_with_stdio(0);
exctime = clock();
#ifdef DEBUG
// freopen("debug.txt", "w", stderr);
#else
// freopen("problem.in", "r", stdin);
// freopen("problem.out", "w", stdout);
#endif
}
__attribute__((destructor)) void after_main() {
#ifdef DEBUG
cerr <<"\nTime: "<<fixed<<setprecision(3)<<double(clock()-exctime)/CLOCKS_PER_SEC<<'\n';
#endif
}
// #define DEBUG
#ifdef DEBUG
// #include </Users/ansar/Desktop/Ansar/misc/debug.h>
#pragma GCC optimize("O0")
#define ED "\033[0m"
#define RED "\033[31m" /* Red */
#define GRN "\033[32m" /* Green */
#define YLW "\033[33m" /* Yellow */
#define CYN "\033[36m" /* Cyan */
#define BLD "\033[1m" /* Bold */
#define BP cerr << "<===>\n"
#define val(x) cerr << (#x) << ": " << x <<endl;
void debug(const auto &... r) {
cerr << BLD << "|=";
((cerr << r << " "), ..., (cerr << ED << endl));
}
void println(const auto &... r) {
((cerr << BLD << r << " "), ..., (cerr << ED << endl));
}
void print(const auto &... r) {
((cerr << BLD << r << " "), ..., (cerr << ED));
}
double time() {
return 1.0 * clock() / CLOCKS_PER_SEC;
}
#else
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
// #pragma GCC target("avx2")
// #pragma GCC optimize("Ofast")
#define debug(...)
#define print(...)
#define println(...)
#define time()
#define val()
#define BP
#endif
typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <db, db> pdd;
typedef pair <ld, ld> pld;
typedef string str;
typedef bitset<64> bin;
#define lb lower_bound // <=
#define ub upper_bound // <
#define sr sort
#define rv reverse
#define nl endl
#define pb push_back
#define eb emplace_back
#define in insert
#define rm erase
#define mp make_pair
#define np next_permutation
#define et empty
#define sz size
#define f first
#define s second
#define y1 yyyyy
#define cont continue
#define sync ios_base::sync_with_stdio(0), cin.tie(NULL)
#define is(ad) ((ad) ? "Yes" : "No")
#define IS(ad) ((ad) ? "YES" : "NO")
#define even(ad) (~(ad)&1)
#define odd(ad) ((ad)&1)
#define updiv(ad, bd) ((((ad) - 1) / (bd) ) + 1)
#define mod(ad, bd) ((((ad) % (bd)) + (bd)) % (bd))
#define mxz(ad, bd) ((ad) < (bd) ? (ad) = (bd), 1 : 0)
#define mnz(ad, bd) ((ad) > (bd) ? (ad) = (bd), 1 : 0)
#define min(ad, bd) ((ad) < (bd) ? (ad) : (bd))
#define max(ad, bd) ((ad) > (bd) ? (ad) : (bd))
#define all(ad) (ad).begin(), (ad).end()
#define arr(ad, bd, cd) ((ad) + (bd)), ((ad) + (bd) + (cd))
#define sorts(ad) sort(all(ad))
#define sorta(ad, bd, cd) sort(arr(ad, bd, cd))
#define sortsby(ad, bd) sort(all(ad),[&](const auto&l, const auto&r){return (bd);})
#define sortaby(ad, bd, cd, dd) sort(arr(ad, bd, cd),[&](const auto&l, const auto&r){return (dd);})
#define rvs(ad) reverse(all(ad))
#define rva(ad, bd, cd) reverse(arr(ad, bd, cd))
#define gl(ad) getline(cin, ad)
#define wfloat(ad) fixed << setprecision(ad)
#define infile(ad) freopen(#ad".in", "r", stdin);
#define outfile(ad) freopen(#ad".out", "w", stdout);
#define traverse(ad, bd) for (auto &a : x)
const int dx[] = {0, 1, 0, -1, 1, -1, -1, 1};
const int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
template <typename T>
inline T gcd(T a, T b) { while (b != 0) swap(b, a %= b); return a; }
template <typename T, typename D>
ostream& operator<<(ostream& os,const pair<T,D>&p){os<<p.f<<" "<<p.s;return os;}
template <typename T>
ostream& operator<<(ostream& os,const vector<T>&v){for(T x:v)os<<x<<' ';return os;}
template <typename T>
ostream& operator<<(ostream& os,const set<T>&v){for(T x:v)os<<x<<' ';return os;}
// g++ t.cpp -std=c++20 -DDEBUG -o o.out -DI -DO
const ll LINF = 1e18; //infinity
const double EPS = 1e-6 ; //epsilon
const double PI = 3.14159; //pi
const ll BS = 31 ; //hashbase
const ll LG = 11; //logarithm
const int INF = 1e9; //infinity
const ll M = 1e9 + 7; //mod
inline ll binpow(ll a,ll n){ll x = 1;while(n){if(n&1)(x*=a)%=M;(a*=a)%=M;n>>=1;}return x%M;}
inline ll Plus(const auto &... r){ll res=0;(((res+=r)%=M), ...);return res;}
inline ll Mult(const auto &... r){ll res=1;(((res*=r)%=M), ...);return res;}
inline ll Div(const auto &... r){ll res=1;res=Mult(binpow(r,M-2)...);return res;}
const ll N = 2e5 + 9; //maxn
const ll Q = 2e5; //maxnq
ll n, T, nq;
set <int> mex;
int mx = 1;
vector <pii> v, w;
map <int, pii> s;
ll lastans = 0;
vector <int> qL[Q], qR[Q];
vector <pii> q[Q];
int qmx[Q];
int t[N], a[N], b[N], k[N];
void add(int i) {
ll L = (a[i]^(T*lastans)), R = (b[i]^(T*lastans));
if (R < L)
swap(L, R);
v.pb({L, R});
s[mx++] = {L, R};
}
void remove(int i) {
w.pb(s[a[i]]);
s.erase(a[i]);
}
ll get(int I) {
ll L = a[I]^(T*lastans), R = b[I]^(T*lastans), K = k[I], ans = 0;
if (R < L)
swap(L, R);
if (R-L+1 < K)
return 0;
for (auto p : v) {
if (min(p.s, R) - max(p.f, L) + 1 >= K) {
ans++;
}
}
for (auto p : w) {
if (min(p.s, R) - max(p.f, L) + 1 >= K) {
ans--;
}
}
ll Q = 0;
while (Q <= nq && qmx[Q] < K)
Q++;
if (Q > nq) {
return lastans = ans;
}
for (auto p : q[Q]) {
if (min(p.s, R) - max(p.f, L) + 1 >= K) {
ans++;
}
}
for (int i = Q+1; i <= nq; ++i) {
if (qL[i].et())
break;
ll invR = (lb(all(qR[i]), L+K-1) - qR[i].begin());
ll invL = (qL[i].end() - ub(all(qL[i]), R-K+1));
ans += (qL[i].sz()-invL-invR);
}
return lastans = ans;
}
void recalc(int I) {
v.clear();
w.clear();
for (int i = 0; i <= nq; ++i) {
qL[i].clear();
qR[i].clear();
q[i].clear();
qmx[i] = 0;
}
vector <pii> qq;
for (auto x : s) {
qq.pb(x.s);
}
sort(all(qq), [](pii a, pii b){return a.s-a.f+1 < b.s-b.f+1;});
for (int i = 0; i < qq.sz(); ++i) {
qL[i/nq].pb(qq[i].f);
qR[i/nq].pb(qq[i].s);
q[i/nq].pb(qq[i]);
qmx[i/nq] = max(qmx[i/nq], qq[i].s-qq[i].f+1);
}
for (int i = 0; i <= nq; ++i) {
sorts(qL[i]);
sorts(qR[i]);
}
}
int main() {
cin >> n >> T;
for (int i = 1; i <= n; ++i) {
cin >> t[i] >> a[i];
if (t[i] != 2)
cin >> b[i];
if (t[i] == 3)
cin >> k[i];
}
int lg = 0;
while ((1 << lg) < n)
lg++;
nq = sqrt(n*lg)+10;
bool flag = 1;
for (int i = 1; i <= n; ++i) {
if (t[i] == 1)
add(i);
if (t[i] == 2)
remove(i);
if (t[i] == 3) {
cout << get(i) << '\n';
}
if (i % nq == 0) {
recalc(i);
}
}
}
/*
NOTES
recalc V
add ?
remove ?
get V
*/
컴파일 시 표준 에러 (stderr) 메시지
segments.cpp:144:22: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
144 | inline ll Plus(const auto &... r){ll res=0;(((res+=r)%=M), ...);return res;}
| ^~~~
segments.cpp:145:22: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
145 | inline ll Mult(const auto &... r){ll res=1;(((res*=r)%=M), ...);return res;}
| ^~~~
segments.cpp:146:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
146 | inline ll Div(const auto &... r){ll res=1;res=Mult(binpow(r,M-2)...);return res;}
| ^~~~
segments.cpp: In function 'void recalc(int)':
segments.cpp:225:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
225 | for (int i = 0; i < qq.sz(); ++i) {
| ~~^~~~~~~~~
segments.cpp: In function 'int main()':
segments.cpp:250:10: warning: unused variable 'flag' [-Wunused-variable]
250 | bool flag = 1;
| ^~~~
# | 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... |