이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
const int N = 2e9;
struct ordered_set{
vector<int> a;
void init(){
a = {};
}
void add(int x){
a.pb(x);
}
int get(int x){
int out = 0;
for (int i: a){
out += (i <= x);
}
return out;
}
int get(int l, int r){
return get(r) - get(l - 1);
}
};
struct DS{
struct node{
int l, r;
ordered_set st, ln;
node(){
l = r = 0;
st.init();
ln.init();
}
};
vector<node> all;
ordered_set al;
int cc = 0, rt, rt1;
int cr(){
all.pb(node());
return ++cc;
}
void init(){
all.pb(node());
rt = cr();
rt1 = cr();
}
void add(int v, int tl, int tr, int& l, int& r){
all[v].st.add(r);
all[v].ln.add(r - l + 1);
if (tl == tr) return;
int tm = (tl + tr) / 2;
if (l <= tm){
if (!all[v].l) all[v].l = cr();
if (v >= all.size()) exit(0);
add(all[v].l, tl, tm, l, r);
}
else {
if (!(all[v].r)) all[v].r = cr();
add(all[v].r, tm + 1, tr, l, r);
}
}
void add1(int v, int tl, int tr, int& l, int& r){
all[v].ln.add(r - l + 1);
if (tl == tr) return;
int tm = (tl + tr) / 2;
if (r <= tm){
if (!all[v].l) all[v].l = cr();
add1(all[v].l, tl, tm, l, r);
}
else {
if (!(all[v].r)) all[v].r = cr();
add1(all[v].r, tm + 1, tr, l, r);
}
}
void add(int l, int r){
add(rt, 1, N, l, r);
add1(rt1, 1, N, l, r);
al.add(r - l + 1);
}
int get1(int v, int tl, int tr, int l, int r, int k){
if (l > tr || r < tl) return 0;
if (l <= tl && tr <= r){
return all[v].st.get(k, N);
}
int tm = (tl + tr) / 2, s = 0;
if (all[v].l) s += get1(all[v].l, tl, tm, l, r, k);
if (all[v].r) s += get1(all[v].r, tm + 1, tr, l, r, k);
return s;
}
int get1(int l, int r){
return get1(rt, 1, N, 1, l, r);
}
int get2(int v, int tl, int tr, int l, int r, int k){
if (l > tr || r < tl || l > r) return 0;
if (l <= tl && tr <= r){
return all[v].ln.get(k, N);
}
int tm = (tl + tr) / 2, s = 0;
if (all[v].l) s += get2(all[v].l, tl, tm, l, r, k);
if (all[v].r) s += get2(all[v].r, tm + 1, tr, l, r, k);
return s;
}
int get2(int l, int r, int k){
if (l > r) return 0;
return al.get(k, N) - get2(rt, 1, N, 1, l - 1, k) - get2(rt1, 1, N, r + 1, N, k);
}
int get(int l, int r, int k){
if ((r - l + 1) < k) return 0;
return get1(l, l + k - 1) + get1(r - k + 1, r) + get2(l + 1, r - 1, k);
}
};
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int q, cc = 0, out = 0; bool t; cin>>q>>t;
vector<pii> f = {{0, 0}};
DS T1, T2; T1.init(); T2.init();
while (q--){
int type; cin>>type;
if (type == 1){
int l, r; cin>>l>>r;
l = (l ^ (t * out));
r = (r ^ (t * out));
if (l > r) swap(l, r);
T1.add(l, r);
f[++cc] = {l, r};
}
else if (type == 2){
int i; cin>>i;
T2.add(f[i].ff, f[i].ss);
}
else {
int l, r, k; cin>>l>>r>>k;
l = (l ^ (t * out));
r = (r ^ (t * out));
if (l > r) swap(l, r);
out = T1.get(l, r, k) - T2.get(l, r, k);
cout<<out<<"\n";
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
segments.cpp: In member function 'void DS::add(int, int, int, int&, int&)':
segments.cpp:59:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<DS::node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | if (v >= all.size()) exit(0);
| ~~^~~~~~~~~~~~~
# | 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... |