# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
414943 |
2021-05-31T10:50:20 Z |
Ruxandra985 |
Joker (BOI20_joker) |
C++14 |
|
2000 ms |
8148 KB |
#include <bits/stdc++.h>
#define DIMN 400010
using namespace std;
int tt[DIMN];
int sz[DIMN] , opt[DIMN];
int n , m , where;
pair <int , int> mch[DIMN];
vector <pair <int , int> > s;
vector <int> v;
int root (int x){
while (tt[x] != x)
x = tt[x];
return x;
}
inline void unite (int x, int y){
int radx = x, rady = y;
if (sz[radx] < sz[rady])
swap (radx,rady);
s.push_back(make_pair(radx,rady)); /// stiva pt undo
sz[radx] += sz[rady];
tt[rady] = radx;
}
inline int unite_init (int x , int y){
int radx = root(x) , radnx , rady = root(y) , radny;
if (radx == rady)
return 0;
radnx = root(n + x);
radny = root(n + y);
unite(radx , radny);
unite(rady , radnx);
return 1;
}
void solve (int st , int dr , int l , int r , int ok){
int mid = (st + dr)/2 , i , poz , x , y , init , init2 , now = ok;
//printf ("%d %d\n" , st , dr);
init = s.size();
for (i = min(dr , m) ; i >= mid ; i--)
now &= unite_init(mch[i].first , mch[i].second);
if (!now){ /// din start nu e ok
opt[mid] = l; /// care clar va fi 0
poz = l;
}
else {
poz = l;
for (i = l + 1 ; i <= r && i < mid ; i++){
x = mch[i].first;
y = mch[i].second;
if (!unite_init(x , y))
break;
poz = i;
}
opt[mid] = poz;
}
while (s.size() != init){
x = s.back().first, y = s.back().second;
s.pop_back();
sz[x] -= sz[y];
tt[y] = y;
}
now = ok;
for (i = min(dr , m) ; i >= mid ; i--)
now &= unite_init(mch[i].first , mch[i].second);
if (st <= mid - 1)
solve (st , mid - 1 , l , poz , now);
while (s.size() != init){
x = s.back().first, y = s.back().second;
s.pop_back();
sz[x] -= sz[y];
tt[y] = y;
}
now = ok;
if (mid + 1 <= dr){
for (i = l + 1 ; i <= poz ; i++){
x = mch[i].first;
y = mch[i].second;
now &= unite_init (x , y);
//v.push_back(i);
}
solve(mid + 1 , dr , poz , r , now);
while (s.size() != init){
x = s.back().first, y = s.back().second;
s.pop_back();
sz[x] -= sz[y];
tt[y] = y;
}
}
/// convine sa te duci mai intai in dreapta, pastrezi tot ce ai adaugat
}
int main()
{
FILE *fin = stdin;
FILE *fout = stdout;
int q , i , l , r;
fscanf (fin,"%d%d%d",&n,&m,&q);
for (i = 1 ; i <= m ; i++){
fscanf (fin,"%d%d",&mch[i].first,&mch[i].second);
}
/// opt se calculeaza intre 1 si M + 1
for (i = 1 ; i <= 2 * n ; i++){
tt[i] = i;
sz[i] = 1;
}
solve (1 , m + 1 , 0 , m , 1); /// te asiguri ca dreapta nu cauzeaza ciclu impar
for (;q;q--){
fscanf (fin,"%d%d",&l,&r);
if (opt[r + 1] >= l - 1 && r + 1 > where)
fprintf (fout,"NO\n");
else fprintf (fout,"YES\n");
}
return 0;
}
Compilation message
Joker.cpp: In function 'void solve(int, int, int, int, int)':
Joker.cpp:74:21: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
74 | while (s.size() != init){
| ~~~~~~~~~^~~~~~~
Joker.cpp:93:21: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
93 | while (s.size() != init){
| ~~~~~~~~~^~~~~~~
Joker.cpp:116:25: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
116 | while (s.size() != init){
| ~~~~~~~~~^~~~~~~
Joker.cpp:45:54: warning: unused variable 'init2' [-Wunused-variable]
45 | int mid = (st + dr)/2 , i , poz , x , y , init , init2 , now = ok;
| ^~~~~
Joker.cpp: In function 'int main()':
Joker.cpp:134:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
134 | fscanf (fin,"%d%d%d",&n,&m,&q);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:136:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
136 | fscanf (fin,"%d%d",&mch[i].first,&mch[i].second);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:149:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
149 | fscanf (fin,"%d%d",&l,&r);
| ~~~~~~~^~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Execution timed out |
2068 ms |
8148 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |