# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
726023 |
2023-04-18T10:15:02 Z |
Cookie |
Werewolf (IOI18_werewolf) |
C++14 |
|
680 ms |
169480 KB |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#include <cstdio>
#include <cstdlib>
#include <vector>
//#include "werewolf.h"
namespace {
int read_int() {
int x;
if (scanf("%d", &x) != 1) {
fprintf(stderr, "Error while reading input\n");
exit(1);
}
return x;
}
} // namespace
const int mxn = 7e5;
int pl[mxn + 1], pr[mxn + 1], n;
vt<int>adj[mxn + 1], adjl[mxn + 1], adjr[mxn + 1];
vt<pii>ql[mxn + 1], qr[mxn + 1];
int tonodel[mxn + 1], tonoder[mxn + 1], tt = 0;
int tinl[mxn + 1], toutl[mxn + 1], tinr[mxn + 1], toutr[mxn + 1], rootl[mxn + 1], rootr[mxn + 1];
int fpl(int u){
if(pl[u] == u)return(u);
return(pl[u] = fpl(pl[u]));
}
int fpr(int u){
if(pr[u] == u)return(u);
return(pr[u] = fpr(pr[u]));
}
void unonl(int u, int v){
v = fpl(v);
if(u == v)return;
pl[v] = u; adjl[u].pb(v);
}
void unonr(int u, int v){
v = fpr(v);
if(u == v)return;
pr[v] = u; adjr[u].pb(v);
}
void dfsl(int s){
if(s < n){
tinl[s] = ++tt; tonodel[tt] = s;
}
else tinl[s] = 2 * n;
for(auto i: adjl[s]){
dfsl(i); tinl[s] = min(tinl[s], tinl[i]);
}
toutl[s] = tt;
}
void buildl(){
for(int i = 0; i < n; i++)pl[i] = i;
for(int i = n - 1; i >= 0; i--){
int pos = n + i;
pl[pos] = pos;
unonl(pos, i);
for(auto j: adj[i]){
if(j > i){
unonl(pos, j);
}
}
for(auto [u, id]: ql[i]){
int U = fpl(u); rootl[id] = U;
}
}
pl[2 * n] = 2 * n;
for(int i = 0; i <= n - 1; i++){
unonl(2 * n, i);
}
dfsl(2 * n);
}
void dfsr(int s){
if(s < n){
tinr[s] = ++tt; tonoder[tt] = s;
}
else tinr[s] = 2 * n;
for(auto i: adjr[s]){
dfsr(i); tinr[s] = min(tinr[s], tinr[i]);
}
toutr[s] = tt;
}
void buildr(){
for(int i = 0; i < n; i++)pr[i] = i;
for(int i = 0; i < n; i++){
int pos = n + i; pr[pos] = pos;
unonr(pos, i);
for(auto j: adj[i]){
if(j < i){
unonr(pos, j);
}
}
for(auto [u, id]: qr[i]){
int U = fpr(u);
rootr[id] = U;
}
}
tt = 0; pr[2 * n] = 2 * n;
for(int i = 0; i < n; i++){
unonr(2 * n, i);
}
dfsr(2 * n);
}
struct Events{
int type, y, l, r, id;
bool operator <(const Events &b){
if(y == b.y){
return(type > b.type);
}
return(y < b.y);
}
};
int bit[mxn + 1], before[mxn + 1], after[mxn + 1];
void upd(int p, int v){
while(p <= mxn){
bit[p] += v;
p += p & (-p);
}
}
int get(int p){
int ans = 0;
while(p){
ans += bit[p];
p -= p & (-p);
}
return(ans);
}
vt<Events>events;
vt<int>check_validity(int N, vt<int>x, vt<int>y, vt<int>s, vt<int>e, vt<int>l, vt<int>r){
n = N;
for(int i = 0; i < x.size(); i++){
adj[x[i]].pb(y[i]);
adj[y[i]].pb(x[i]);
}
for(int i = 0; i < l.size(); i++){
ql[l[i]].pb(make_pair(s[i], i));
qr[r[i]].pb(make_pair(e[i], i));
}
buildl();
buildr();
for(int i = 0; i < l.size(); i++){
events.pb({1, tinr[rootr[i]], tinl[rootl[i]], toutl[rootl[i]], i});
events.pb({-1, toutr[rootr[i]], tinl[rootl[i]], toutl[rootl[i]], i});
}
for(int i = 0; i < n; i++){
events.pb({0, tinr[i], tinl[i], -1, -1});
}
sort(events.begin(), events.end());
for(auto [type, y, l, r, id]: events){
if(type == 0){
upd(l, 1);
}else if(type == 1){
before[id] = get(r) - get(l - 1);
}else{
after[id] = get(r) - get(l - 1);
}
}
vt<int>ans;
for(int i = 0; i < l.size(); i++){
ans.pb((bool)(before[i] < after[i]));
}
return(ans);
}
Compilation message
werewolf.cpp: In function 'void buildl()':
werewolf.cpp:81:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
81 | for(auto [u, id]: ql[i]){
| ^
werewolf.cpp: In function 'void buildr()':
werewolf.cpp:119:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
119 | for(auto [u, id]: qr[i]){
| ^
werewolf.cpp: In function 'std::vector<int> check_validity(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
werewolf.cpp:158:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
158 | for(int i = 0; i < x.size(); i++){
| ~~^~~~~~~~~~
werewolf.cpp:162:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
162 | for(int i = 0; i < l.size(); i++){
| ~~^~~~~~~~~~
werewolf.cpp:171:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
171 | for(int i = 0; i < l.size(); i++){
| ~~^~~~~~~~~~
werewolf.cpp:180:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
180 | for(auto [type, y, l, r, id]: events){
| ^
werewolf.cpp:191:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
191 | for(int i = 0; i < l.size(); i++){
| ~~^~~~~~~~~~
werewolf.cpp: At global scope:
werewolf.cpp:21:5: warning: 'int {anonymous}::read_int()' defined but not used [-Wunused-function]
21 | int read_int() {
| ^~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
82680 KB |
Output is correct |
2 |
Correct |
42 ms |
82568 KB |
Output is correct |
3 |
Correct |
42 ms |
82540 KB |
Output is correct |
4 |
Correct |
42 ms |
82636 KB |
Output is correct |
5 |
Correct |
40 ms |
82672 KB |
Output is correct |
6 |
Correct |
48 ms |
82632 KB |
Output is correct |
7 |
Correct |
45 ms |
82668 KB |
Output is correct |
8 |
Correct |
41 ms |
82620 KB |
Output is correct |
9 |
Correct |
42 ms |
82616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
82680 KB |
Output is correct |
2 |
Correct |
42 ms |
82568 KB |
Output is correct |
3 |
Correct |
42 ms |
82540 KB |
Output is correct |
4 |
Correct |
42 ms |
82636 KB |
Output is correct |
5 |
Correct |
40 ms |
82672 KB |
Output is correct |
6 |
Correct |
48 ms |
82632 KB |
Output is correct |
7 |
Correct |
45 ms |
82668 KB |
Output is correct |
8 |
Correct |
41 ms |
82620 KB |
Output is correct |
9 |
Correct |
42 ms |
82616 KB |
Output is correct |
10 |
Correct |
46 ms |
83788 KB |
Output is correct |
11 |
Correct |
48 ms |
83880 KB |
Output is correct |
12 |
Correct |
45 ms |
83840 KB |
Output is correct |
13 |
Correct |
47 ms |
83884 KB |
Output is correct |
14 |
Correct |
50 ms |
83880 KB |
Output is correct |
15 |
Correct |
52 ms |
84016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
619 ms |
151312 KB |
Output is correct |
2 |
Correct |
589 ms |
163056 KB |
Output is correct |
3 |
Correct |
528 ms |
160780 KB |
Output is correct |
4 |
Correct |
562 ms |
159876 KB |
Output is correct |
5 |
Correct |
579 ms |
159832 KB |
Output is correct |
6 |
Correct |
616 ms |
159708 KB |
Output is correct |
7 |
Correct |
532 ms |
157268 KB |
Output is correct |
8 |
Correct |
532 ms |
163240 KB |
Output is correct |
9 |
Correct |
503 ms |
159848 KB |
Output is correct |
10 |
Correct |
480 ms |
158596 KB |
Output is correct |
11 |
Correct |
489 ms |
159020 KB |
Output is correct |
12 |
Correct |
543 ms |
159552 KB |
Output is correct |
13 |
Correct |
551 ms |
164412 KB |
Output is correct |
14 |
Correct |
500 ms |
164356 KB |
Output is correct |
15 |
Correct |
552 ms |
164408 KB |
Output is correct |
16 |
Correct |
585 ms |
164468 KB |
Output is correct |
17 |
Correct |
621 ms |
157464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
82680 KB |
Output is correct |
2 |
Correct |
42 ms |
82568 KB |
Output is correct |
3 |
Correct |
42 ms |
82540 KB |
Output is correct |
4 |
Correct |
42 ms |
82636 KB |
Output is correct |
5 |
Correct |
40 ms |
82672 KB |
Output is correct |
6 |
Correct |
48 ms |
82632 KB |
Output is correct |
7 |
Correct |
45 ms |
82668 KB |
Output is correct |
8 |
Correct |
41 ms |
82620 KB |
Output is correct |
9 |
Correct |
42 ms |
82616 KB |
Output is correct |
10 |
Correct |
46 ms |
83788 KB |
Output is correct |
11 |
Correct |
48 ms |
83880 KB |
Output is correct |
12 |
Correct |
45 ms |
83840 KB |
Output is correct |
13 |
Correct |
47 ms |
83884 KB |
Output is correct |
14 |
Correct |
50 ms |
83880 KB |
Output is correct |
15 |
Correct |
52 ms |
84016 KB |
Output is correct |
16 |
Correct |
619 ms |
151312 KB |
Output is correct |
17 |
Correct |
589 ms |
163056 KB |
Output is correct |
18 |
Correct |
528 ms |
160780 KB |
Output is correct |
19 |
Correct |
562 ms |
159876 KB |
Output is correct |
20 |
Correct |
579 ms |
159832 KB |
Output is correct |
21 |
Correct |
616 ms |
159708 KB |
Output is correct |
22 |
Correct |
532 ms |
157268 KB |
Output is correct |
23 |
Correct |
532 ms |
163240 KB |
Output is correct |
24 |
Correct |
503 ms |
159848 KB |
Output is correct |
25 |
Correct |
480 ms |
158596 KB |
Output is correct |
26 |
Correct |
489 ms |
159020 KB |
Output is correct |
27 |
Correct |
543 ms |
159552 KB |
Output is correct |
28 |
Correct |
551 ms |
164412 KB |
Output is correct |
29 |
Correct |
500 ms |
164356 KB |
Output is correct |
30 |
Correct |
552 ms |
164408 KB |
Output is correct |
31 |
Correct |
585 ms |
164468 KB |
Output is correct |
32 |
Correct |
621 ms |
157464 KB |
Output is correct |
33 |
Correct |
638 ms |
160844 KB |
Output is correct |
34 |
Correct |
297 ms |
130408 KB |
Output is correct |
35 |
Correct |
611 ms |
163508 KB |
Output is correct |
36 |
Correct |
609 ms |
160352 KB |
Output is correct |
37 |
Correct |
647 ms |
162644 KB |
Output is correct |
38 |
Correct |
619 ms |
160864 KB |
Output is correct |
39 |
Correct |
617 ms |
169480 KB |
Output is correct |
40 |
Correct |
680 ms |
166680 KB |
Output is correct |
41 |
Correct |
544 ms |
162208 KB |
Output is correct |
42 |
Correct |
587 ms |
159104 KB |
Output is correct |
43 |
Correct |
623 ms |
167308 KB |
Output is correct |
44 |
Correct |
596 ms |
162604 KB |
Output is correct |
45 |
Correct |
577 ms |
168788 KB |
Output is correct |
46 |
Correct |
519 ms |
168620 KB |
Output is correct |
47 |
Correct |
549 ms |
164556 KB |
Output is correct |
48 |
Correct |
472 ms |
164336 KB |
Output is correct |
49 |
Correct |
524 ms |
164528 KB |
Output is correct |
50 |
Correct |
644 ms |
164440 KB |
Output is correct |
51 |
Correct |
613 ms |
166496 KB |
Output is correct |
52 |
Correct |
605 ms |
166300 KB |
Output is correct |