結果

問題 No.1768 The frog in the well knows the great ocean.
ユーザー TKTYITKTYI
提出日時 2021-11-26 23:46:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,103 bytes
コンパイル時間 4,155 ms
コンパイル使用メモリ 247,288 KB
実行使用メモリ 9,644 KB
最終ジャッジ日時 2023-09-12 06:03:25
合計ジャッジ時間 9,310 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
9,644 KB
testcase_01 AC 35 ms
4,380 KB
testcase_02 AC 34 ms
4,376 KB
testcase_03 AC 34 ms
4,376 KB
testcase_04 AC 30 ms
4,380 KB
testcase_05 AC 33 ms
4,376 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:37:23: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   37 |       if(r==u)for(auto[key,val]:M[v])M[u][key]+=val;
      |                       ^
main.cpp:38:20: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   38 |       else for(auto[key,val]:M[u])M[v][key]+=val;
      |                    ^
main.cpp:50:27: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   50 |           if(r==u)for(auto[key,val]:M[v])M[u][key]+=val;
      |                           ^
main.cpp:51:24: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   51 |           else for(auto[key,val]:M[u])M[v][key]+=val;
      |                        ^
main.cpp:55:27: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   55 |           if(r==u)for(auto[key,val]:M[v])M[u][key]+=val;
      |                           ^
main.cpp:56:24: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   56 |           else for(auto[key,val]:M[u])M[v][key]+=val;
      |                        ^

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long int ll;
typedef long double ld;
#define FOR(i,l,r) for(ll i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,l,r) for(ll i=r-1;i>=l;i--)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
#define BS(A,x) binary_search(ALL(A),x)
#define LB(A,x) (ll)(lower_bound(ALL(A),x)-A.begin())
#define UB(A,x) (ll)(upper_bound(ALL(A),x)-A.begin())
#define COU(A,x) (UB(A,x)-LB(A,x))
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
//using mint=modint1000000007;
using mint=modint998244353;
void chmax(ll&a,ll b){a=max(a,b);}
void chmin(ll&a,ll b){a=min(a,b);}
signed main(){
  ll T;cin>>T;
  while(T--){
    ll N;cin>>N;
    vector<ll>A(N),B(N);
    REP(i,N)cin>>A[i];REP(i,N)cin>>B[i];
    set<ll>S;REP(i,N)S.insert(A[i]);
    bool x=1;
    REP(i,N)x=x&&count(ALL(S),B[i])&&A[i]<=B[i];
    vector<map<ll,ll>>M(N);dsu D(N);
    REP(i,N)M[i][A[i]]++;
    REP(i,N-1)if(B[i]==B[i+1]){
      ll u=D.leader(i),v=D.leader(i+1),r=D.merge(u,v);
      if(r==u)for(auto[key,val]:M[v])M[u][key]+=val;
      else for(auto[key,val]:M[u])M[v][key]+=val;
    }
    vector<vector<ll>>X(N+1);
    REP(i,N)if(i==0||B[i-1]!=B[i])X[B[i]].emplace_back(i);
    RREP(v,N+1){
      for(auto i:X[v]){
        ll l=i,r=N-1;
        while(l!=r){
          ll m=(l+r+1)/2;if(D.same(i,m))l=m;else r=m-1;
        }
        if(i&&B[i-1]>B[i]){
          ll u=D.leader(i-1),v=D.leader(i),r=D.merge(u,v);
          if(r==u)for(auto[key,val]:M[v])M[u][key]+=val;
          else for(auto[key,val]:M[u])M[v][key]+=val;
        }
        if(l<N-1&&B[l+1]>B[l]){
          ll u=D.leader(l+1),v=D.leader(l),r=D.merge(l,l+1);
          if(r==u)for(auto[key,val]:M[v])M[u][key]+=val;
          else for(auto[key,val]:M[u])M[v][key]+=val;
        }
        //cout<<i<<" "<<l<<endl;
        x=x&&M[D.leader(i)][v];
        //cout<<M[D.leader(i)][v]<<endl;
      }
    }
    if(x)cout<<"Yes"<<endl;else cout<<"No"<<endl;
  }
  return 0;
}
0