Submission #599655

# Submission time Handle Problem Language Result Execution time Memory
599655 2022-07-19T17:56:04 Z MohammadAghil Inside information (BOI21_servers) C++17
0 / 100
16 ms 21600 KB
      #include <bits/stdc++.h>
//   #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
    using namespace std;
  typedef long long ll;
   typedef pair<int, int> pp;
    #define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
      #define per(i,r,l) for(int i = (r); i >= (l); i--)
        #define rep(i,l,r) for(int i = (l); i < (r); i++)
           #define all(x) begin(x), end(x)
              #define sz(x) (int)(x).size()
                  #define pb push_back
                      #define ss second
                           #define ff first
                                   void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
void IOS(){
     cin.tie(0) -> sync_with_stdio(0);
     #ifndef ONLINE_JUDGE
          freopen("in.in", "r", stdin);
          freopen("out.out", "w", stdout);
     #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 1e9 + 7, maxn = 3e5 + 5, lg = 22, inf = ll(1e9) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;}
 
int fen[maxn];
vector<int> his;
void upd(int i, bool add = true){
     if(add) his.pb(i);
     for(i++; i < maxn; i += i&-i) fen[i] += add?1:-1;
}
int get(int i){
     int res = 0;
     for(i++; i; i -= i&-i) res += fen[i];
     return res;
}
 
vector<pp> adj[maxn];
vector<pp> query1[maxn];
vector<int> query2[maxn];
int cnt[maxn], id[maxn], tp[maxn], ans[maxn], n;
bool ban[maxn], rc[maxn], cr[maxn];
 
void dfs(int r, int p = -1, bool st = true){ //
     cnt[r] = st?1:-1;
     for(auto[c, t]: adj[r]) if(!ban[c] && c - p) dfs(c, r, st), cnt[r] += st?cnt[c]:0;
}

int find_cent(int r, int p, int tot){ //
     for(auto[c, t]: adj[r]) if(c - p && !ban[c] && (cnt[c]<<1) > tot) return find_cent(c, r, tot);
     return r;
}
 
void dfs2(int r, int p, int ID){
     id[r] = ID;
     if(r - ID){
          rc[r] = rc[p]&(tp[r] > tp[p]);
          cr[r] = cr[p]&(tp[r] < tp[p]);
     }
     for(auto[c, t]: adj[r]) if(c - p && !ban[c]) tp[c] = t, dfs2(c, r, ID); 
}
 
vector<int> tmp;
 
void dfs3(int r, int p){
     if(rc[r]) tmp.pb(tp[r]);
     for(auto[c, t]: query1[r]) if(cnt[c] + 1 && id[c] == -1){
          ans[t] = cr[r]&(tp[id[r]] < t);
     } else if(cnt[c] + 1 && tp[id[c]] > tp[id[r]]){
          ans[t] = cr[r]&rc[c]&(tp[c] < t);
     }
     for(int t: query2[r]) if(cr[r] && tp[id[r]] < t){
          ans[t] += get(t);
     }
     for(auto[c, t]: adj[r]) if(c - p && !ban[c]) dfs3(c, r);
}
 
void reset(int r){
     for(int c: his) upd(c, false);
     his.clear();
     dfs(r, -1, false);
     ban[r] = true;
}
 
void dec(int r){
     dfs(r);
     r = find_cent(r, -1, cnt[r]);
     sort(all(adj[r]), [&](pp a, pp b){ return a.ss > b.ss; });
     rc[r] = cr[r] = true, id[r] = -1;
     for(auto[c, t]: adj[r]) if(!ban[c]) rc[c] = cr[c] = true, tp[c] = t, dfs2(c, r, c);
     upd(r);
     for(auto[c, t]: adj[r]) if(!ban[c]){
          dfs3(c, r);
          for(int v: tmp) upd(v);
          tmp.clear();
     }
     for(auto[c, t]: query1[r]) if(cnt[c] + 1 && rc[c] && t > tp[c]) ans[t] = true;
     for(int t: query2[r]) ans[t] += get(t);
     reset(r);
     for(auto[c, t]: adj[r]) if(!ban[c]) dec(c);
}
 
int main(){ IOS();
     int k; cin >> n >> k;
     vector<int> ty(n+k);
     rep(i,0,n+k-1){
          char c; cin >> c;
          if(c == 'S'){
               int u, v; cin >> u >> v; u--, v--;
               adj[u].pb({v, i}), adj[v].pb({u, i});
          }else if(c == 'Q'){
               ty[i] = 1;
               int u, v; cin >> u >> v; u--, v--;
               if(u - v) query1[v].pb({u, i});
               else ans[i] = 1;
          }else{
               ty[i] = 2;
               int d; cin >> d; d--;
               query2[d].pb(i);
          }
     }
     dec(0);
     rep(i,0,n+k-1) if(ty[i]){
          if(ty[i]&1) cout << (ans[i]?"yes":"no") << '\n';
          else cout << ans[i] << '\n';
     }
     return 0; 
}

Compilation message

servers.cpp: In function 'void IOS()':
servers.cpp:19:18: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |           freopen("in.in", "r", stdin);
      |           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
servers.cpp:20:18: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |           freopen("out.out", "w", stdout);
      |           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 21588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 21588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 21588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 21588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 21588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 21588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 21588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 21588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 21540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 21540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 21600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 21600 KB Output isn't correct
2 Halted 0 ms 0 KB -