이 제출은 이전 버전의 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;
const int S = 1500;
// 1) l1 <= l && r1 >= k + l - 1
// 2) l1 є [l + 1, r - k + 1] && r1 - l1 >= k - 1
struct DS{
vector<pii> all, f, st;
vector<int> L, R;
vector<int> R1[150], R2[150];
void add(int l, int r){
all.pb({l, r}); f.pb({l, r});
if (all.size() == S){
st.clear();
for (int i = 0; i < L.size(); i++){
st.pb({L[i], R[i]});
}
for (auto [l1, r1]: all){
st.pb({l1, r1});
}
sort(st.begin(), st.end());
L.clear(); R.clear();
for (auto [l1, r1]: st){
L.pb(l1); R.pb(r1);
}
int l1 = 0, r1 = S - 1, cc = 0;
while (r1 < L.size()){
R1[cc].clear();
R2[cc].clear();
for (int i = l1; i <= r1; i++){
R1[i].pb(R[i]);
R2[i].pb(R[i] - L[i]);
}
sort(R1[cc].begin(), R1[cc].end());
sort(R2[cc].begin(), R2[cc].end());
l1 += S; r1 += S; cc++;
}
all.clear();
}
}
vector<int> :: iterator it;
int g(int t, int k){ // l1 є [1, t] && r1 - l1 >= k
if (L.empty()) return 0;
it = upper_bound(L.begin(), L.end(), t);
int j = (int) (it - L.begin()) - 1, out = 0;
int l1 = 0, r1 = S - 1, cc = 0;
while (true){
if (r1 >= j){
for (int i = l1; i <= j; i++){
out += ((f[i].ss - f[i].ff) >= k);
}
break;
}
it = lower_bound(R2[cc].begin(), R2[cc].end(), k);
out += (int) (R2[cc].end() - it);
l1 += S; r1 += S; cc++;
}
return out;
}
int get(int l, int r, int k){
if ((r - l + 1) < k) return 0;
int out = 0;
if (!L.empty()){
it = upper_bound(L.begin(), L.end(), l);
int j = (int) (it - L.begin()) - 1;
int l1 = 0, r1 = S - 1, cc = 0;
while (true){
if (r1 >= j){
for (int i = l1; i <= j; i++){
out += (f[i].ss >= (l + k - 1));
}
break;
}
it = lower_bound(R1[cc].begin(), R1[cc].end(), l + k - 1);
out += (int) (R1[cc].end() - it);
l1 += S; r1 += S; cc++;
}
}
out += (g(r - k + 1, k - 1) - g(l, k - 1));
for (auto [l1, r1]: all){
out += ((min(r, r1) - max(l, l1) + 1) >= k);
}
return out;
}
};
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int q, out = 0; bool t; cin>>q>>t;
vector<pii> f = {{0, 0}};
DS T1, T2;
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.pb({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)':
segments.cpp:22:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for (int i = 0; i < L.size(); i++){
| ~~^~~~~~~~~~
segments.cpp:34:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | while (r1 < L.size()){
| ~~~^~~~~~~~~~
# | 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... |