이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pii pair<int, int>
#define X first
#define Y second
#define pb push_back
using namespace std;
const int SQR = 450;
const int N = 2 * 1e5 + 10;
int n, xr, lastans, pos[N];
int b_cnt; //num. of buckets
int cnt; //num of diff. intervals
bool ban[N];
pii intv[N];
vector<vector<int>> lft, rgt;
vector<pii> bkt, bkt2, add;
vector<int> vl, vr, rem;
int intersect(pii a, pii b){
if(a.X > b.X || (a.X == b.X && a.Y > b.Y)){
swap(a.X, b.X);
swap(a.Y, b.Y);
}
if(a.Y > b.Y) return b.Y - b.X + 1;
return a.Y - b.X + 1;
}
void bucket(){
for(int x : rem) ban[x] = true;
sort(add.begin(), add.end());
int p1 = 0;
int p2 = 0;
lft.clear();
rgt.clear();
while(p1 < add.size() || p2 < bkt.size()){
if(p1 < add.size() && p2 < bkt.size()){
if(add[p1].X < bkt[p2].X){
bkt2.pb(add[p1]);
p1++;
} else {
bkt2.pb(bkt[p2]);
p2++;
}
} else if(p1 < add.size()){
bkt2.pb(add[p1]);
p2++;
} else {
bkt2.pb(bkt[p2]);
p2++;
}
}
bkt.clear();
for(pii x : bkt2){
if(!ban[x.Y])
bkt.pb(x);
}
bkt2.clear();
for(pii x : bkt){
vl.pb(intv[x.Y].X);
vr.pb(intv[x.Y].Y);
if(vl.size() >= SQR){
sort(vl.begin(), vl.end());
sort(vr.begin(), vr.end());
lft.pb(vl);
rgt.pb(vr);
vl.clear();
vr.clear();
}
}
if(!vl.empty()){
sort(vl.begin(), vl.end());
sort(vr.begin(), vr.end());
lft.pb(vl);
rgt.pb(vr);
vl.clear();
vr.clear();
}
for(int x : rem) ban[x] = false;
rem.clear();
add.clear();
b_cnt = lft.size();
}
int main(){
for(int i = 0; i < N; i++) pos[i] = i / SQR;
scanf("%d%d", &n, &xr);
//cout << intersect({1, 2}, {2, 3}) << "\n";
for(int i = 0; i < n; i++){
int t;
cin >> t;
if(t == 1){
int l, r;
scanf("%d%d", &l, &r);
l = l ^ (t * lastans);
r = r ^ (t * lastans);
if(l > r) swap(l, r);
intv[++cnt] = {l, r};
add.pb({r - l + 1, cnt});
} else if(t == 2){
int ind;
scanf("%d", &ind);
rem.pb(ind);
} else {
int l, r, k;
int ans = 0;
scanf("%d%d%d", &l, &r, &k);
l = l ^ (t * lastans);
r = r ^ (t * lastans);
if(l > r) swap(l, r);
for(int x : rem)
if(intersect(intv[x], {l, r}) >= k) ans--;
for(pii x : add){
//cout << intv[x.Y].X << " " << intv[x.Y].Y << " " << l << " " << r << ": " << intersect(intv[x.Y], {l, r}) << "\n";
if(intersect(intv[x.Y], {l, r}) >= k) ans++;
}
int lo = 0, hi = b_cnt - 1;
while(hi - lo > 1){
int mi = (lo + hi) / 2;
if(bkt[mi].X < k)
lo = mi;
else
hi = mi;
}
int b = pos[lo];
while(lo < bkt.size() && pos[lo] == b){
if(intersect(intv[bkt[lo].Y], {l, r}) >= k);
lo++;
}
b++;
for(b; b < b_cnt; b++){
ans += lft[b].size();
ans -= upper_bound(rgt[b].begin(), rgt[b].end(), l + k) - rgt[b].begin();
ans -= lft[b].end() - upper_bound(lft[b].begin(), lft[b].end(), r - k);
}
cout << ans << "\n";
lastans = ans;
}
if(add.size() + rem.size() >= SQR){
bucket();
}
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
segments.cpp: In function 'void bucket()':
segments.cpp:41:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | while(p1 < add.size() || p2 < bkt.size()){
| ~~~^~~~~~~~~~~~
segments.cpp:41:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | while(p1 < add.size() || p2 < bkt.size()){
| ~~~^~~~~~~~~~~~
segments.cpp:42:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | if(p1 < add.size() && p2 < bkt.size()){
| ~~~^~~~~~~~~~~~
segments.cpp:42:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | if(p1 < add.size() && p2 < bkt.size()){
| ~~~^~~~~~~~~~~~
segments.cpp:50:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | } else if(p1 < add.size()){
| ~~~^~~~~~~~~~~~
segments.cpp: In function 'int main()':
segments.cpp:144:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
144 | while(lo < bkt.size() && pos[lo] == b){
| ~~~^~~~~~~~~~~~
segments.cpp:149:8: warning: statement has no effect [-Wunused-value]
149 | for(b; b < b_cnt; b++){
| ^
segments.cpp:97:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
97 | scanf("%d%d", &n, &xr);
| ~~~~~^~~~~~~~~~~~~~~~~
segments.cpp:106:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
106 | scanf("%d%d", &l, &r);
| ~~~~~^~~~~~~~~~~~~~~~
segments.cpp:116:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
116 | scanf("%d", &ind);
| ~~~~~^~~~~~~~~~~~
segments.cpp:121:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
121 | scanf("%d%d%d", &l, &r, &k);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# | 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... |