이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
#define sz(a) (int)a.size()
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mpp make_pair
const ld PI = 3.14159265359, prec = 1e-9;;
//using u128 = __uint128_t;
//const int x[4] = {1, 0, -1, 0};
//const int y[4] = {0, -1, 0, 1};
const ll mod = 1e9 + 7, pr = 31;
const int mxn = 2e5 + 5, mxq = 1e5 + 5, sq = 1000, mxv = 5e4 + 1;
//const int base = (1 <<18);
const ll inf = 1e18 + 5, neg = -69420, inf2 = 1e14;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
// have fun!
//https://usaco.org/current/data/sol_prob2_gold_open24.html
struct th{
int len, l, r;
bool operator <(const th &other){
return(len < other.len);
}
};
vt<th>all;
int n, t;
int lseg[mxn + 1], rseg[mxn + 1];
multiset<pii>seg;
vt<pii>more, bad;
vt<int>lp[sq + 1], rp[sq + 1];
void add(){
all.clear();
for(auto [l, r]: seg)all.pb({r - l + 1, l, r});
sort(ALL(all));
for(int i = 0; i < sq; i++){
lp[i].clear(); rp[i].clear();
}
for(int i = 0; i < sz(all); i++){
lp[i / sq].pb(all[i].l); rp[i / sq].pb(all[i].r);
}
for(int i = 0; i < sq; i++){
sort(ALLR(lp[i])); sort(ALL(rp[i]));
}
more.clear(); bad.clear();
}
int solve(int l, int r, int k){
if(r - l + 1 < k)return(0);
int ans = 0;
for(int i = 0; i <= (sz(all) - 1) / sq; i++){
if(all[i * sq].len < k && all[min((i + 1) * sq - 1, sz(all) - 1)].len >= k){
for(int j = i * sq; j <= min((i + 1) * sq - 1, sz(all) - 1); j++){
if(all[j].len >= k && all[j].r >= l + k - 1 && all[j].l <= r - k + 1)ans++;
}
}else if(all[i * sq].len >= k){
ans += sz(lp[i]);
int le = 0, ri = sz(lp[i]) - 1, res = -1;
while(le <= ri){
int mid = (le + ri) >> 1;
if(lp[i][mid] > r - k + 1){
res = mid; le = mid + 1;
}else{
ri = mid - 1;
}
}
ans -= (res + 1);
le = 0, ri = sz(rp[i]) - 1, res = -1;
while(le <= ri){
int mid = (le + ri) >> 1;
if(rp[i][mid] < l + k - 1){
res = mid; le = mid + 1;
}else{
ri = mid - 1;
}
}
ans -= (res + 1);
}
}
for(auto [le, ri]: more){
if(ri - le + 1 >= k && le <= r - k + 1 && ri >= l + k - 1)ans++;
}
for(auto [le, ri]: bad){
if(ri - le + 1 >= k && le <= r - k + 1 && ri >= l + k - 1)ans--;
}
return(ans);
}
void solve(){
cin >> n >> t;
all.pb({-1, 0, 0});
int last = 0, idseg = 0;
while(n--){
int idq; cin >> idq;
if(idq == 1){
int a, b; cin >> a >> b;
a = (a ^ (t * last)); b = (b ^ (t * last));
if(a > b)swap(a, b);
lseg[++idseg] = a; rseg[idseg] = b;
more.pb(mpp(a, b)); seg.insert(mpp(a, b));
}else if(idq == 2){
int id; cin >> id;
seg.erase(seg.find(mpp(lseg[id], rseg[id]))); bad.pb(mpp(lseg[id], rseg[id]));
}else{
int l, r, k; cin >> l >> r >> k;
l = (l ^ (t * last)), r = (r ^ (t * last));
if(l > r)swap(l, r);
last = solve(l, r, k);
//cout << l << " " << r << " " << k << "\n";
cout << last << "\n";
}
if(sz(more) + sz(bad) == sq){
add();
}
}
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("DATA.inp", "r", stdin);
//freopen("DATA.out", "w", stdout);
int tt; tt = 1;
while(tt--){
solve();
}
return(0);
}
컴파일 시 표준 에러 (stderr) 메시지
segments.cpp: In function 'void add()':
segments.cpp:44:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
44 | for(auto [l, r]: seg)all.pb({r - l + 1, l, r});
| ^
segments.cpp: In function 'int solve(int, int, int)':
segments.cpp:94:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
94 | for(auto [le, ri]: more){
| ^
segments.cpp:100:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
100 | for(auto [le, ri]: bad){
| ^
# | 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... |