답안 #254140

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
254140 2020-07-29T12:00:21 Z Nucleist Tenis (COI19_tenis) C++14
51 / 100
500 ms 10104 KB
//Self-control leads to consistency.
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define EPS 0.000001
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
void setIO(string s) {
  ios_base::sync_with_stdio(0); cin.tie(0); 
  freopen((s+".in").c_str(),"r",stdin);
  freopen((s+".out").c_str(),"w",stdout);
}
ll seg[400011];
ll ari[400011];
pair<int,dos> zi[400011];
void upd(ll p,ll l,ll r,ll k,ll val){
  if(l==r && l==k){
    seg[p]=val;
    return;
  }
  ll med=(l+r)>>1;
  if(k<=med){
    upd(p*2,l,med,k,val);
  }
  else upd(p*2+1,med+1,r,k,val);
  seg[p]=max(seg[p*2],seg[p*2+1]);
}
ll query(ll p,ll l,ll r,ll l1,ll r1){
  if(l>r || l>r1 || l1>r)return 0;
  if(l>=l1 && r<=r1)return seg[p];
  ll med=(l+r)>>1;
  return max(query(p*2,l,med,l1,r1),query(p*2+1,med+1,r,l1,r1));
}
int main()
{
  flash;
  ll n,q;
  cin>>n>>q;
  for (ll i = 0; i < n; ++i)
  {
    ll yo;
    cin>>yo;
    yo--;
    ari[i]=yo;
    zi[yo].first=i;
  }
  for (ll i = 0; i < n; ++i)
  {
    ll yo;
    cin>>yo;
    yo--;
    zi[yo].second.first=i;
  }
  for (ll i = 0; i < n; ++i)
  {
    ll yo;
    cin>>yo;
    yo--;
    zi[yo].second.second=i;
  }
  for (int i = 0; i < n; ++i)
  {
    upd(1,0,n-1,zi[i].first,max(zi[i].second.first,zi[i].second.second));
  }
  ll l=0,r=0;
  set<ll>ans;
  while(query(1,0,n-1,l,r)+1!=(r-l+1)){
    ll cur=query(1,0,n-1,l,r);
    r++;
  }
  for (ll i = 0; i <= r; ++i)
  {
    ans.insert(ari[i]);
  }
  while(q--){
    ll na;
    cin>>na;
    if(na==1){
      ll x;
      cin>>x;
      x--;
      if(ans.find(x)!=ans.end()){
        cout<<"DA"<<'\n';
      }
      else cout<<"NE"<<'\n';
    }
    else{
      int x,y,z;
      cin>>x>>y>>z;
      y--,z--;
      if(x==1){
        ari[zi[y].first]=z;
        ari[zi[z].first]=y;
        swap(zi[y].first,zi[z].first);
      }
      if(x==2)swap(zi[y].second.first,zi[z].second.first);
      if(x==3)swap(zi[y].second.second,zi[z].second.second);
      upd(1,0,n-1,zi[y].first,max(zi[y].second.first,zi[y].second.second));
      upd(1,0,n-1,zi[z].first,max(zi[z].second.first,zi[z].second.second));
      ll l1=0,r1=0;
      ans.clear();
      while(query(1,0,n-1,l1,r1)+1!=(r1-l1+1)){
        ll cur=query(1,0,n-1,l1,r1);
        r1++;
      }
      for (ll i = 0; i <= r1; ++i)
      {
        ans.insert(ari[i]);
      }
    }
  }
  return 0;
}

Compilation message

tenis.cpp:5:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("O3")
 
tenis.cpp:6:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("unroll-loops")
 
tenis.cpp: In function 'int main()':
tenis.cpp:86:8: warning: unused variable 'cur' [-Wunused-variable]
     ll cur=query(1,0,n-1,l,r);
        ^~~
tenis.cpp:121:12: warning: unused variable 'cur' [-Wunused-variable]
         ll cur=query(1,0,n-1,l1,r1);
            ^~~
tenis.cpp: In function 'void setIO(std::__cxx11::string)':
tenis.cpp:28:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen((s+".in").c_str(),"r",stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tenis.cpp:29:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen((s+".out").c_str(),"w",stdout);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 252 ms 8312 KB Output is correct
14 Correct 317 ms 9208 KB Output is correct
15 Correct 76 ms 6008 KB Output is correct
16 Correct 93 ms 6520 KB Output is correct
17 Correct 53 ms 5496 KB Output is correct
18 Correct 53 ms 5496 KB Output is correct
19 Correct 49 ms 5496 KB Output is correct
20 Correct 107 ms 6136 KB Output is correct
21 Correct 52 ms 5624 KB Output is correct
22 Correct 73 ms 5752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 113 ms 8184 KB Output is correct
2 Correct 83 ms 6136 KB Output is correct
3 Correct 83 ms 6008 KB Output is correct
4 Correct 88 ms 5836 KB Output is correct
5 Correct 76 ms 5880 KB Output is correct
6 Correct 72 ms 5880 KB Output is correct
7 Correct 73 ms 5880 KB Output is correct
8 Correct 71 ms 5880 KB Output is correct
9 Correct 100 ms 6136 KB Output is correct
10 Correct 78 ms 5880 KB Output is correct
11 Correct 95 ms 6904 KB Output is correct
12 Correct 78 ms 5752 KB Output is correct
13 Correct 74 ms 5880 KB Output is correct
14 Correct 82 ms 5880 KB Output is correct
15 Correct 83 ms 6008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 252 ms 8312 KB Output is correct
14 Correct 317 ms 9208 KB Output is correct
15 Correct 76 ms 6008 KB Output is correct
16 Correct 93 ms 6520 KB Output is correct
17 Correct 53 ms 5496 KB Output is correct
18 Correct 53 ms 5496 KB Output is correct
19 Correct 49 ms 5496 KB Output is correct
20 Correct 107 ms 6136 KB Output is correct
21 Correct 52 ms 5624 KB Output is correct
22 Correct 73 ms 5752 KB Output is correct
23 Correct 113 ms 8184 KB Output is correct
24 Correct 83 ms 6136 KB Output is correct
25 Correct 83 ms 6008 KB Output is correct
26 Correct 88 ms 5836 KB Output is correct
27 Correct 76 ms 5880 KB Output is correct
28 Correct 72 ms 5880 KB Output is correct
29 Correct 73 ms 5880 KB Output is correct
30 Correct 71 ms 5880 KB Output is correct
31 Correct 100 ms 6136 KB Output is correct
32 Correct 78 ms 5880 KB Output is correct
33 Correct 95 ms 6904 KB Output is correct
34 Correct 78 ms 5752 KB Output is correct
35 Correct 74 ms 5880 KB Output is correct
36 Correct 82 ms 5880 KB Output is correct
37 Correct 83 ms 6008 KB Output is correct
38 Execution timed out 1083 ms 10104 KB Time limit exceeded
39 Halted 0 ms 0 KB -