Submission #68941529


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ex exit(0)
#define ln cout<<'\n'
#define ll long long
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.12f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

void Init() {}
void Main() {
  ll T;
  R T;
  map<ll,PP> ma;
  ma[0]=PP(0,P(-1,-1));
  ma[-1]=PP(-1,P(-1,-1));
  REP(i,1,T+1) {
    ll z,x,y;
    R z;
    if(z==1) {
      R x;
      PP p=ma[x];
      ma[i]=PP(i,P(-1,-1));
      ma[i].S.F=x;
      if(p.S.S!=-1) {
        PP q=ma[p.S.S];
        q.S.F=x;
        ma[p.S.S]=q;
        ma[i].S.S=p.S.S;
      }
      ma[x].S.S=i;
    } else {
      cin >> x >> y;
      PP p=ma[x],q=ma[y];
      vector<ll> a,b;
      ll f=0;
      while(1) {
        p=ma[p.S.S];
        q=ma[q.S.S];
        if(p.F==y) break;
        a.pb(p.F);
        if(q.F==x) {f=1;break;}
        b.pb(q.F);
      }
      ll ans=0;
      if(!f) {
        rep(j,a.size()) {
          ans+=a[j];
          ma.erase(a[j]);
        }
        ma[x].S.S=y;
        ma[y].S.F=x;
      } else {
        rep(j,b.size()) {
          ans+=b[j];
          ma.erase(b[j]);
        }
        ma[x].S.F=y;
        ma[y].S.S=x;
      }
      pr(ans);
    }
  }
  /*
  map<ll,PP> ma;
  map<long double,ll> m;
  ma[0]=PP(0,1LL<<60);
  m[0]=0;
  REP(i,1,T+1) {
    ll z,x,y;
    R z;
    if(z==1) {
      R x;
      PP p=ma[x];
      long double d=p.F+p.S;
      p.S/=2;
      ma[x]=p;
      ma[i]=P(d,p.S);
      m[d]=i;
    } else {
      cin >> x >> y;
      PP p=ma[x],q=ma[y];
      long double l=p.F,r=q.F;
      if(l>r) swap(l,r);
      iter(m) it=m.upper_bound(l);
      ll ans=0;
      vector<ll> v1;
      vector<long double> v2;
      while(it!=m.end()&&it->F!=r) {
        ans+=it->S;
        v1.pb(it->S);
        v2.pb(it->F);
        it++;
      }
      pr(ans);
      rep(i,v1.size()) ma.erase(v1[i]);
      rep(i,v2.size()) m.erase(v2[i]);
    }
  }
  */
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Init();ll T=1;if(0)R T;while(T--)Main();return 0;}

Submission Info

Submission Time
Task F - Erase between X and Y
User kzyKT
Language C++ 20 (gcc 12.2)
Score 525
Code Size 2818 Byte
Status AC
Exec Time 801 ms
Memory 50308 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 525 / 525
Status
AC × 3
AC × 36
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 03_handmade_00.txt, 03_handmade_01.txt, 03_handmade_02.txt, 03_handmade_03.txt, 03_handmade_04.txt, 03_handmade_05.txt, 03_handmade_06.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3420 KiB
00_sample_01.txt AC 1 ms 3456 KiB
00_sample_02.txt AC 1 ms 3468 KiB
01_random_00.txt AC 69 ms 3472 KiB
01_random_01.txt AC 81 ms 3476 KiB
01_random_02.txt AC 83 ms 3536 KiB
01_random_03.txt AC 86 ms 3436 KiB
01_random_04.txt AC 90 ms 3492 KiB
01_random_05.txt AC 94 ms 3496 KiB
01_random_06.txt AC 99 ms 3536 KiB
01_random_07.txt AC 105 ms 3568 KiB
01_random_08.txt AC 112 ms 3432 KiB
01_random_09.txt AC 116 ms 3392 KiB
01_random_10.txt AC 123 ms 3420 KiB
01_random_11.txt AC 130 ms 3480 KiB
01_random_12.txt AC 137 ms 3608 KiB
01_random_13.txt AC 143 ms 3428 KiB
01_random_14.txt AC 149 ms 3496 KiB
01_random_15.txt AC 157 ms 3372 KiB
01_random_16.txt AC 163 ms 3440 KiB
01_random_17.txt AC 170 ms 3548 KiB
01_random_18.txt AC 180 ms 3560 KiB
01_random_19.txt AC 197 ms 3452 KiB
01_random_20.txt AC 801 ms 42480 KiB
02_random2_00.txt AC 319 ms 22896 KiB
02_random2_01.txt AC 341 ms 23012 KiB
02_random2_02.txt AC 314 ms 22988 KiB
02_random2_03.txt AC 294 ms 31676 KiB
02_random2_04.txt AC 284 ms 37092 KiB
03_handmade_00.txt AC 1 ms 3464 KiB
03_handmade_01.txt AC 323 ms 42532 KiB
03_handmade_02.txt AC 398 ms 42480 KiB
03_handmade_03.txt AC 427 ms 50308 KiB
03_handmade_04.txt AC 225 ms 22956 KiB
03_handmade_05.txt AC 261 ms 22952 KiB
03_handmade_06.txt AC 244 ms 22896 KiB