답안 #605438

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
605438 2022-07-25T17:36:29 Z AmirElarbi 늑대인간 (IOI18_werewolf) C++14
49 / 100
1018 ms 36744 KB
#include <bits/stdc++.h>
#define vi vector<int>
#define gi greater<int>
#define gr greater
#define ve vector
#define ll long long
#define vf vector<float>
#define vll vector<pair<ll,ll>>
#define ii pair<int,int>
#define pll pair<ll,ll>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 1e9
#define eps 1e-7
#define eps1 1e-2
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 2e5+5
using namespace std;
const int MOD = 1e9+7;
const int nax = 2e5+5;
typedef complex<int> Point;
//#define X real()
//#define Y imag()
#include "werewolf.h"
vi fin, adj[nax];
ii st[nax*4];
int ind[nax];
void dfs(int u, int p){
    fin.pb(u);
    for(auto x : adj[u]){
        if(x == p) continue;
        dfs(x,u);
    }
}
void build(int v,int l, int r){
    if(l ==r) {
        st[v].fi = st[v].se = fin[l];
        return;
    }
    int md = (l+r)/2;
    build(v*2, l, md);
    build(v*2+1, md+1, r);
    st[v].fi = max(st[v*2].fi, st[v*2+1].fi);
    st[v].se = min(st[v*2].se, st[v*2+1].se);
}
int query(int v, int l, int r, int i, int j, int ind){
    if(i > j) swap(i,j);
    if(r < i ||l > j) {
        if(ind) return INF;
        else return 0;
    }
    if(i <= l && r <= j){
        if(ind) return st[v].se;
        else return st[v].fi;
    }
    int md = (l+r)/2;
    if(!ind) return max(query(v*2,l,md,i,j,ind), query(v*2+1, md+1, r, i, j, ind));
    else return min(query(v*2,l,md,i,j,ind), query(v*2+1, md+1, r, i, j, ind));
}
bool vis[nax][2];
void dfs2(int u, int l, int r, bool ind){
    if(vis[u][ind]) return;
    vis[u][ind] = 1;
    for(auto x : adj[u]){
        if(ind == 1 && x <= r) dfs2(x,l,r,1);
        else if(ind == 0 && l <= x) dfs2(x,l,r,0);
    }
}
vi check_validity(int n, vi x, vi y, vi s, vi e, vi low,vi high) {

    int m = x.size();
    for (int i = 0; i < m; ++i)
    {
        adj[x[i]].pb(y[i]);
        adj[y[i]].pb(x[i]);
    }
    int q = s.size();
    vi a(q,0);
    if(n <=3000 && m<=6000 && q<=3000){
        for (int i = 0; i < q; ++i)
        {
            memset(vis,0,sizeof vis);
            dfs2(s[i], low[i], high[i],0);
            dfs2(e[i], low[i], high[i],1); 
            for (int j = 0; j < n; ++j)
            {
                if(vis[j][0] && vis[j][1]) {a[i] = 1; break;}
            }
        }
        return a;
    }
    for (int i = 0; i < n; ++i)
    {
        if(adj[i].size() == 1){
            dfs(i,i);
            break;
        }
    }
    build(1,0,n-1);
    for (int i = 0; i < n; ++i)
    {
        ind[fin[i]] = i;
    }
    
    for (int i = 0; i < q; ++i) {
        int l = min(ind[e[i]],ind[s[i]]), r = max(ind[e[i]],ind[s[i]])+1;
        while(l < r){
            int md = (l+r)/2;
            int mn = query(1,0,n-1, ind[s[i]], md, 1), mx = query(1,0,n-1, md, ind[e[i]], 0);
            //cout << mn << " " << mx << " " << md << endl;
            if(mn < low[i] && mx > high[i]){
                a[i] = 0;
                break;
            } else if(mn < low[i]){
                if(ind[s[i]] < ind[e[i]]) r = md;
                else l = md+1;
            } else if(mx > high[i]) {
                if(ind[s[i]] < ind[e[i]]) l = md+1;
                else r = md;
            } else{
                if(mx >= low[i] || mn <= high[i]) a[i] = 1;
                else a[i] = 0;
                break;
            }
        }
    }
    return a;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5332 KB Output is correct
2 Correct 4 ms 5332 KB Output is correct
3 Correct 4 ms 5332 KB Output is correct
4 Correct 4 ms 5396 KB Output is correct
5 Correct 4 ms 5332 KB Output is correct
6 Correct 4 ms 5332 KB Output is correct
7 Correct 5 ms 5396 KB Output is correct
8 Correct 4 ms 5392 KB Output is correct
9 Correct 5 ms 5332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5332 KB Output is correct
2 Correct 4 ms 5332 KB Output is correct
3 Correct 4 ms 5332 KB Output is correct
4 Correct 4 ms 5396 KB Output is correct
5 Correct 4 ms 5332 KB Output is correct
6 Correct 4 ms 5332 KB Output is correct
7 Correct 5 ms 5396 KB Output is correct
8 Correct 4 ms 5392 KB Output is correct
9 Correct 5 ms 5332 KB Output is correct
10 Correct 284 ms 5768 KB Output is correct
11 Correct 202 ms 5732 KB Output is correct
12 Correct 51 ms 5876 KB Output is correct
13 Correct 299 ms 5772 KB Output is correct
14 Correct 242 ms 5732 KB Output is correct
15 Correct 299 ms 5924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 391 ms 36576 KB Output is correct
2 Correct 446 ms 36668 KB Output is correct
3 Correct 458 ms 36672 KB Output is correct
4 Correct 862 ms 36744 KB Output is correct
5 Correct 1018 ms 36656 KB Output is correct
6 Correct 989 ms 36672 KB Output is correct
7 Correct 659 ms 36672 KB Output is correct
8 Correct 500 ms 36704 KB Output is correct
9 Correct 546 ms 36680 KB Output is correct
10 Correct 587 ms 36660 KB Output is correct
11 Correct 854 ms 36672 KB Output is correct
12 Correct 789 ms 36672 KB Output is correct
13 Correct 498 ms 36700 KB Output is correct
14 Correct 541 ms 36544 KB Output is correct
15 Correct 463 ms 36664 KB Output is correct
16 Correct 569 ms 36544 KB Output is correct
17 Correct 716 ms 36668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5332 KB Output is correct
2 Correct 4 ms 5332 KB Output is correct
3 Correct 4 ms 5332 KB Output is correct
4 Correct 4 ms 5396 KB Output is correct
5 Correct 4 ms 5332 KB Output is correct
6 Correct 4 ms 5332 KB Output is correct
7 Correct 5 ms 5396 KB Output is correct
8 Correct 4 ms 5392 KB Output is correct
9 Correct 5 ms 5332 KB Output is correct
10 Correct 284 ms 5768 KB Output is correct
11 Correct 202 ms 5732 KB Output is correct
12 Correct 51 ms 5876 KB Output is correct
13 Correct 299 ms 5772 KB Output is correct
14 Correct 242 ms 5732 KB Output is correct
15 Correct 299 ms 5924 KB Output is correct
16 Correct 391 ms 36576 KB Output is correct
17 Correct 446 ms 36668 KB Output is correct
18 Correct 458 ms 36672 KB Output is correct
19 Correct 862 ms 36744 KB Output is correct
20 Correct 1018 ms 36656 KB Output is correct
21 Correct 989 ms 36672 KB Output is correct
22 Correct 659 ms 36672 KB Output is correct
23 Correct 500 ms 36704 KB Output is correct
24 Correct 546 ms 36680 KB Output is correct
25 Correct 587 ms 36660 KB Output is correct
26 Correct 854 ms 36672 KB Output is correct
27 Correct 789 ms 36672 KB Output is correct
28 Correct 498 ms 36700 KB Output is correct
29 Correct 541 ms 36544 KB Output is correct
30 Correct 463 ms 36664 KB Output is correct
31 Correct 569 ms 36544 KB Output is correct
32 Correct 716 ms 36668 KB Output is correct
33 Incorrect 398 ms 35972 KB Output isn't correct
34 Halted 0 ms 0 KB -