#define DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}
// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
public:
template<typename T>
_Debug& operator,(T val) {
cout << val << endl;
return *this;
}
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif
// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back
// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;
// ---------- END OF TEMPLATE ----------
int X[1500000],Y[1500000],A[1500000];
vpii updates,queries;
pii ans[1500000];
class comp1 {
public:
bool operator()(int a,int b) {
if (ans[a].first == ans[b].first) return a < b;
else return ans[a].first < ans[b].first;
}
};
class comp2 {
public:
bool operator()(int a,int b) {
if (ans[a].second == ans[b].second) return a < b;
else return ans[a].second < ans[b].second;
}
};
set<int,comp1> S1[1500000];
set<int,comp2> S2[1500000];
map<int,int> MM;
int findAns(int l,int r,vi q,int N) {
if (q.empty()) return 0;
int i;
vi c;
for (i = 0; i < q.size(); i++) {
int s = A[queries[q[i]].first],e = queries[q[i]].second;
if ((e < l) || (s > r)) continue;
if ((l >= s) && (r <= e)) S1[0].insert(q[i]),S2[0].insert(q[i]);
else c.pb(q[i]);
}
if (!S1[0].empty()) {
MM[0] = 0,MM[N] = -1;
int x = 1;
for (i = l; i <= r; i++) {
if (MM.count(updates[i].second)) continue;
int u = (--MM.lower_bound(updates[i].second))->second;
MM[updates[i].second] = x++;
if (updates[i].first == 1) {
auto it = S2[u].begin(),it2 = S2[u].end();
int f = -1;
while (1) {
if ((it != S2[u].end()) && (ans[*it].second < N-updates[i].second)) it++;
else {
f = 0;
break;
}
if ((it2 == S2[u].begin()) || (ans[*(--it2)].second < N-updates[i].second)) {
f = 1;
break;
}
}
if (f) {
swap(S1[u],S1[x-1]),swap(S2[u],S2[x-1]);
it2 = S2[x-1].end();
while ((it2 != S2[x-1].begin()) && (ans[*(--it2)].second >= N-updates[i].second)) {
S1[u].insert(*it2),S2[u].insert(*it2);
S1[x-1].erase(*it2),it2 = S2[x-1].erase(it2);
}
}
else {
it = S2[u].begin();
while ((it != S2[u].end()) && (ans[*it].second < N-updates[i].second)) {
S1[x-1].insert(*it),S2[x-1].insert(*it);
S1[u].erase(*it),it = S2[u].erase(it);
}
}
}
else {
auto it = S1[u].begin(),it2 = S1[u].end();
int f = -1;
while (1) {
if ((it != S1[u].end()) && (ans[*it].first < updates[i].second)) it++;
else {
f = 0;
break;
}
if ((it2 == S1[u].begin()) || (ans[*(--it2)].first < updates[i].second)) {
f = 1;
break;
}
}
if (f) {
it2 = S1[u].end();
while ((it2 != S1[u].begin()) && (ans[*(--it2)].first >= updates[i].second)) {
S1[x-1].insert(*it2),S2[x-1].insert(*it2);
S2[u].erase(*it2),it2 = S1[u].erase(it2);
}
}
else {
swap(S1[u],S1[x-1]),swap(S2[u],S2[x-1]);
it = S1[x-1].begin();
while ((it != S1[x-1].end()) && (ans[*it].first < updates[i].second)) {
S1[u].insert(*it),S2[u].insert(*it);
S2[x-1].erase(*it),it = S1[x-1].erase(it);
}
}
}
}
for (auto it = MM.begin(); it->second != -1; it++) {
auto it2 = it;
it2++;
int x1 = it->first,x2 = it2->first;
for (auto it3 = S1[it->second].begin(); it3 != S1[it->second].end(); it3++) {
ans[*it3].first = max(ans[*it3].first,x1);
ans[*it3].second = max(ans[*it3].second,N-x2);
}
S1[it->second].clear(),S2[it->second].clear();
}
MM.clear();
}
if (l != r) {
int m = (l+r) / 2;
findAns(l,m,c,N),findAns(m+1,r,c,N);
}
return 0;
}
int main() {
int i;
int N,M,Q;
int T,P,L;
scanf("%d %d %d",&N,&M,&Q);
for (i = 0; i < M; i++) scanf("%d %d",&X[i],&Y[i]),A[i] = 0;
for (i = 0; i < Q; i++) {
scanf("%d",&T);
if (T == 1) {
scanf("%d",&P),P--;
queries.pb(mp(P,(int) updates.size()-1));
}
else if (T == 2) {
scanf("%d",&L);
updates.pb(mp(1,N-L));
}
else if (T == 3) {
scanf("%d",&L);
updates.pb(mp(2,L+1));
}
else {
scanf("%d %d",&X[M],&Y[M]);
A[M++] = updates.size();
}
}
vi q;
for (i = 0; i < queries.size(); i++) ans[i] = mp(X[queries[i].first],Y[queries[i].first]),q.pb(i);
findAns(0,(int) updates.size()-1,q,N+1);
for (i = 0; i < queries.size(); i++) printf("%d %d\n",ans[i].first,ans[i].second);
return 0;
}
Compilation message
sweeping.cpp: In function 'int findAns(int, int, vi, int)':
sweeping.cpp:82:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < q.size(); i++) {
~~^~~~~~~~~~
sweeping.cpp: In function 'int main()':
sweeping.cpp:200:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < queries.size(); i++) ans[i] = mp(X[queries[i].first],Y[queries[i].first]),q.pb(i);
~~^~~~~~~~~~~~~~~~
sweeping.cpp:202:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < queries.size(); i++) printf("%d %d\n",ans[i].first,ans[i].second);
~~^~~~~~~~~~~~~~~~
sweeping.cpp:178:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d",&N,&M,&Q);
~~~~~^~~~~~~~~~~~~~~~~~~~~
sweeping.cpp:179:55: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for (i = 0; i < M; i++) scanf("%d %d",&X[i],&Y[i]),A[i] = 0;
~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
sweeping.cpp:181:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&T);
~~~~~^~~~~~~~~
sweeping.cpp:183:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&P),P--;
~~~~~~~~~~~~~~^~~~
sweeping.cpp:187:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&L);
~~~~~^~~~~~~~~
sweeping.cpp:191:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&L);
~~~~~^~~~~~~~~
sweeping.cpp:195:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&X[M],&Y[M]);
~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
141676 KB |
Output is correct |
2 |
Correct |
100 ms |
141560 KB |
Output is correct |
3 |
Correct |
83 ms |
141432 KB |
Output is correct |
4 |
Correct |
97 ms |
141688 KB |
Output is correct |
5 |
Correct |
82 ms |
141436 KB |
Output is correct |
6 |
Correct |
87 ms |
141592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12627 ms |
215644 KB |
Output is correct |
2 |
Correct |
12160 ms |
215628 KB |
Output is correct |
3 |
Correct |
12186 ms |
215720 KB |
Output is correct |
4 |
Correct |
5432 ms |
214988 KB |
Output is correct |
5 |
Correct |
5632 ms |
215372 KB |
Output is correct |
6 |
Correct |
7096 ms |
249792 KB |
Output is correct |
7 |
Correct |
11294 ms |
215880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10135 ms |
206196 KB |
Output is correct |
2 |
Correct |
8779 ms |
223072 KB |
Output is correct |
3 |
Correct |
5639 ms |
222064 KB |
Output is correct |
4 |
Correct |
5007 ms |
222552 KB |
Output is correct |
5 |
Correct |
9196 ms |
222600 KB |
Output is correct |
6 |
Correct |
9227 ms |
222760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10135 ms |
206196 KB |
Output is correct |
2 |
Correct |
8779 ms |
223072 KB |
Output is correct |
3 |
Correct |
5639 ms |
222064 KB |
Output is correct |
4 |
Correct |
5007 ms |
222552 KB |
Output is correct |
5 |
Correct |
9196 ms |
222600 KB |
Output is correct |
6 |
Correct |
9227 ms |
222760 KB |
Output is correct |
7 |
Correct |
11910 ms |
222860 KB |
Output is correct |
8 |
Correct |
12031 ms |
223068 KB |
Output is correct |
9 |
Correct |
11635 ms |
222776 KB |
Output is correct |
10 |
Correct |
6044 ms |
222276 KB |
Output is correct |
11 |
Correct |
5332 ms |
204872 KB |
Output is correct |
12 |
Correct |
9564 ms |
204840 KB |
Output is correct |
13 |
Correct |
8423 ms |
204684 KB |
Output is correct |
14 |
Correct |
285 ms |
153196 KB |
Output is correct |
15 |
Correct |
690 ms |
196560 KB |
Output is correct |
16 |
Correct |
11396 ms |
204868 KB |
Output is correct |
17 |
Correct |
5421 ms |
234960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
141676 KB |
Output is correct |
2 |
Correct |
100 ms |
141560 KB |
Output is correct |
3 |
Correct |
83 ms |
141432 KB |
Output is correct |
4 |
Correct |
97 ms |
141688 KB |
Output is correct |
5 |
Correct |
82 ms |
141436 KB |
Output is correct |
6 |
Correct |
87 ms |
141592 KB |
Output is correct |
7 |
Correct |
12627 ms |
215644 KB |
Output is correct |
8 |
Correct |
12160 ms |
215628 KB |
Output is correct |
9 |
Correct |
12186 ms |
215720 KB |
Output is correct |
10 |
Correct |
5432 ms |
214988 KB |
Output is correct |
11 |
Correct |
5632 ms |
215372 KB |
Output is correct |
12 |
Correct |
7096 ms |
249792 KB |
Output is correct |
13 |
Correct |
11294 ms |
215880 KB |
Output is correct |
14 |
Correct |
10135 ms |
206196 KB |
Output is correct |
15 |
Correct |
8779 ms |
223072 KB |
Output is correct |
16 |
Correct |
5639 ms |
222064 KB |
Output is correct |
17 |
Correct |
5007 ms |
222552 KB |
Output is correct |
18 |
Correct |
9196 ms |
222600 KB |
Output is correct |
19 |
Correct |
9227 ms |
222760 KB |
Output is correct |
20 |
Correct |
11910 ms |
222860 KB |
Output is correct |
21 |
Correct |
12031 ms |
223068 KB |
Output is correct |
22 |
Correct |
11635 ms |
222776 KB |
Output is correct |
23 |
Correct |
6044 ms |
222276 KB |
Output is correct |
24 |
Correct |
5332 ms |
204872 KB |
Output is correct |
25 |
Correct |
9564 ms |
204840 KB |
Output is correct |
26 |
Correct |
8423 ms |
204684 KB |
Output is correct |
27 |
Correct |
285 ms |
153196 KB |
Output is correct |
28 |
Correct |
690 ms |
196560 KB |
Output is correct |
29 |
Correct |
11396 ms |
204868 KB |
Output is correct |
30 |
Correct |
5421 ms |
234960 KB |
Output is correct |
31 |
Correct |
8430 ms |
194324 KB |
Output is correct |
32 |
Correct |
11788 ms |
215724 KB |
Output is correct |
33 |
Correct |
11360 ms |
215864 KB |
Output is correct |
34 |
Correct |
8768 ms |
204136 KB |
Output is correct |
35 |
Correct |
8167 ms |
202820 KB |
Output is correct |
36 |
Correct |
6607 ms |
214940 KB |
Output is correct |
37 |
Correct |
5274 ms |
207800 KB |
Output is correct |
38 |
Correct |
9508 ms |
218692 KB |
Output is correct |
39 |
Correct |
10061 ms |
215496 KB |
Output is correct |
40 |
Correct |
11519 ms |
215688 KB |
Output is correct |