#include <iostream>
#include <stdio.h>
#include <queue>
#include <vector>
#include <set>
using namespace std;
void SubTaskOne(int n, int t);
void SubTaskTwo(int n, int t);
void SubTaskThree(int n, int t);
int FindAns(const multiset<int> & segL, const multiset<int> & segR, int l, int r, int k);
int main()
{
int n, t;
cin>>n>>t;
if (n<=5000)
SubTaskOne(n, t);
else
SubTaskThree(n, t);
char I;
cin >> I;
return 0;
}
void SubTaskOne(int n, int t)
{
int lastans=0;
vector<pair<int, int> > seg;
while (n--)
{
int type, l, r, k, id;
cin>>type;
if (type==1)
{
cin>>l>>r;
l=(l^(t*lastans));
r=(r^(t*lastans));
if (l>r) swap(l, r);
seg.push_back(make_pair(l, r));
}
else if (type==2)
{
cin>>id;
seg[id-1]=make_pair(-1, -1);
}
else if (type==3)
{
int ans=0;
cin>>l>>r>>k;
l=(l^(t*lastans));
r=(r^(t*lastans));
if (l>r) swap(l, r);
for (int i=0; i<seg.size(); i++)
if (seg[i].first!=-1 && min(seg[i].second, r)-max(seg[i].first, l)+1>=k)
ans++;
cout<<ans<<'\n';
lastans=ans;
}
}
}
void SubTaskThree(int n, int t)
{
int lastans=0;
vector<pair<int, int> > a;
multiset<int> a_l, a_r, b_l, b_r;
while (n--)
{
int type, l, r, k, id;
cin>>type;
if (type==1)
{
cin>>l>>r;
l=(l^(t*lastans));
r=(r^(t*lastans));
if (l>r) swap(l, r);
a.push_back(make_pair(l, r));
a_l.insert(l);
a_r.insert(r);
}
else if (type==2)
{
cin>>id;
// b.push_back(a[id-1]);
b_l.insert(a[id-1].first);
b_r.insert(a[id-1].second);
}
else if (type==3)
{
int ans=0;
cin>>l>>r>>k;
l=(l^(t*lastans));
r=(r^(t*lastans));
if (l>r) swap(l, r);
ans=FindAns(a_l, a_r, l, r, k)-FindAns(b_l, b_r, l, r, k);
cout<<ans<<'\n';
lastans=ans;
}
}
}
int FindAns(const multiset<int> & segL, const multiset<int> & segR, int l, int r, int k)
{
if (k==1)
{
int ans=segL.size();
ans-=distance(segL.upper_bound(r), segL.end());
if (segR.size())
{
auto it=segR.lower_bound(l);
if (it!=segR.begin()) ans-=distance(segR.begin(), --it)+1;
}
return ans;
}
}
Compilation message
segments.cpp: In function 'void SubTaskOne(int, int)':
segments.cpp:54:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0; i<seg.size(); i++)
~^~~~~~~~~~~
segments.cpp: In function 'int FindAns(const std::multiset<int>&, const std::multiset<int>&, int, int, int)':
segments.cpp:116:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
10 ms |
376 KB |
Output is correct |
4 |
Correct |
10 ms |
376 KB |
Output is correct |
5 |
Correct |
15 ms |
504 KB |
Output is correct |
6 |
Correct |
17 ms |
504 KB |
Output is correct |
7 |
Correct |
12 ms |
504 KB |
Output is correct |
8 |
Correct |
12 ms |
504 KB |
Output is correct |
9 |
Correct |
12 ms |
504 KB |
Output is correct |
10 |
Correct |
8 ms |
504 KB |
Output is correct |
11 |
Correct |
21 ms |
504 KB |
Output is correct |
12 |
Correct |
21 ms |
504 KB |
Output is correct |
13 |
Correct |
10 ms |
504 KB |
Output is correct |
14 |
Correct |
13 ms |
504 KB |
Output is correct |
15 |
Correct |
10 ms |
504 KB |
Output is correct |
16 |
Correct |
10 ms |
504 KB |
Output is correct |
17 |
Correct |
13 ms |
504 KB |
Output is correct |
18 |
Correct |
10 ms |
632 KB |
Output is correct |
19 |
Correct |
13 ms |
376 KB |
Output is correct |
20 |
Correct |
13 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
257 ms |
6748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5072 ms |
5100 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
244 ms |
8188 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
10 ms |
376 KB |
Output is correct |
4 |
Correct |
10 ms |
376 KB |
Output is correct |
5 |
Correct |
15 ms |
504 KB |
Output is correct |
6 |
Correct |
17 ms |
504 KB |
Output is correct |
7 |
Correct |
12 ms |
504 KB |
Output is correct |
8 |
Correct |
12 ms |
504 KB |
Output is correct |
9 |
Correct |
12 ms |
504 KB |
Output is correct |
10 |
Correct |
8 ms |
504 KB |
Output is correct |
11 |
Correct |
21 ms |
504 KB |
Output is correct |
12 |
Correct |
21 ms |
504 KB |
Output is correct |
13 |
Correct |
10 ms |
504 KB |
Output is correct |
14 |
Correct |
13 ms |
504 KB |
Output is correct |
15 |
Correct |
10 ms |
504 KB |
Output is correct |
16 |
Correct |
10 ms |
504 KB |
Output is correct |
17 |
Correct |
13 ms |
504 KB |
Output is correct |
18 |
Correct |
10 ms |
632 KB |
Output is correct |
19 |
Correct |
13 ms |
376 KB |
Output is correct |
20 |
Correct |
13 ms |
376 KB |
Output is correct |
21 |
Incorrect |
257 ms |
6748 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
10 ms |
376 KB |
Output is correct |
4 |
Correct |
10 ms |
376 KB |
Output is correct |
5 |
Correct |
15 ms |
504 KB |
Output is correct |
6 |
Correct |
17 ms |
504 KB |
Output is correct |
7 |
Correct |
12 ms |
504 KB |
Output is correct |
8 |
Correct |
12 ms |
504 KB |
Output is correct |
9 |
Correct |
12 ms |
504 KB |
Output is correct |
10 |
Correct |
8 ms |
504 KB |
Output is correct |
11 |
Correct |
21 ms |
504 KB |
Output is correct |
12 |
Correct |
21 ms |
504 KB |
Output is correct |
13 |
Correct |
10 ms |
504 KB |
Output is correct |
14 |
Correct |
13 ms |
504 KB |
Output is correct |
15 |
Correct |
10 ms |
504 KB |
Output is correct |
16 |
Correct |
10 ms |
504 KB |
Output is correct |
17 |
Correct |
13 ms |
504 KB |
Output is correct |
18 |
Correct |
10 ms |
632 KB |
Output is correct |
19 |
Correct |
13 ms |
376 KB |
Output is correct |
20 |
Correct |
13 ms |
376 KB |
Output is correct |
21 |
Incorrect |
257 ms |
6748 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |