提出 #51089996


ソースコード 拡げる

/*By Ashok_Zayn اشکنزی-------------------------------------------------------------------
----------------------------------------------------------------------------------------*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define ll long long
#define dbl double
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ff first
#define ss second
#define ins insert
#define vll vector <ll>
#define vvll vector <vll>
#define vbool vector <bool>
#define pll pair <ll,ll>
#define vpll vector <pll>
#define allin(v) v.begin(), v.end()
#define allinr(v) v.rbegin(), v.rend()
#define desc() greater <ll>()
#define rapido ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mll map<ll,ll>
#define umll unorder_map<ll,ll>
#define erase_duplicates(x)             x.erase(unique(allin(x)),x.end());
#define endl "\n"

vll dx = {1, 0, -1, 0};
vll dy = {0, 1, 0, -1};
#define loop(i,a,b,k) for(ll i=a;i<b;i+=k)
#define rloop(i,a,b,k) for(ll i=a;i>=b;i-=k)
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
/*------------------Policy based data structures------------------------------------------*/
template<class T> using oset = tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;
//template<class key, class value> using omap = tree <key,value,less<key>,rb_tree_tag,tree_order_statistics_node_update>;
/*find_by_order(k) -> returns iterator to kth element from start 0
order_of_key(k) -> returns count of elements < k */
 
template<typename T> istream& operator >>(istream &in,vector<T> &v){ for(auto &x:v) in>>x; return in;}
template<typename T> ostream& operator <<(ostream &out,const vector<T> &v){ for(auto &x:v) out<<x<<' '; return out;}
template<typename T1,typename T2> istream& operator >>(istream &in,pair<T1,T2> &p){ in>>p.first>>p.second; return in;}
template<typename T1,typename T2> ostream& operator <<(ostream &out,const pair<T1,T2> &p) {out<<p.first<<' '<<p.second;return out;}
 
/*-----------------Useful Values----------------------------------------------------------*/
const int ebl = 1e9+7;
const int newebl = 998244353;
const int local_n = 1e5+7;
const int global_n = 1e7+5;
const int max_prime = 1e6+3;
const ll inf = 1e18;
const ll eps = 1e-9;
#define PI 3.141592653589793238462
#define modinv2 500000004
 
/*----------------Useful Functions-------------------------------------------------------*/
ll gcd(ll a, ll b) { while (b) {a %= b; swap(a,b);} return a; }
ll lcm(ll a, ll b) { ll g=gcd(a,b); ll res=a*(b/g); return res; }
ll extnd_gcd(ll a,ll b,ll &x,ll &y){if (b==0){ x=1;y=0;return a;}ll x1,y1;ll g=extnd_gcd(b,a%b,x1,y1);x=y1;y=x1-y1*(a/b);return g; }
ll binExp(ll a, ll b, ll m) { a = a % m; ll res = 1; while (b) { if (b&1) { res=(res * a) % m; } a=(a * a) % m; b>>=1; } return res; }
ll mod_inv(ll a, ll m) { a = a % m; return binExp(a,m-2,m); }
ll mod_add(ll a, ll b, ll m) { a = a % m; b = b % m; return (((a + b) % m) + m) % m; }
ll mod_sub(ll a, ll b, ll m) { a = a % m; b = b % m; return (((a - b) % m) + m) % m; }
ll mod_mul(ll a, ll b, ll m) { a = a % m; b = b % m; return (((a * b) % m) + m) % m; }
ll mod_div(ll a, ll b, ll m) { a = a % m; ll binv = mod_inv(b,m); return (((a * binv) % m) + m) % m; }
ll mod(ll n){if(n>=0)return n%ebl;else{ll x=abs(n)/ebl;return (ebl*(x+1)+n)%ebl; }}
ll sqrtll(ll n){ll lo=0,hi=1e9+7; while(hi-lo>1){ll m=(hi+lo)/2;if(m*m<=n){lo=m;}else{hi=m-1;}}if(hi*hi<=n){return hi;}
return lo;}
dbl sqrtld(ll n) { dbl lo=0,hi=1e9+7; while (hi-lo>eps) { dbl m=(hi+lo)/2; if ((n-m*m)>eps) { lo=m; } else { hi=m-eps; }} return lo; }
ll doceil(ll a, ll b){return (a/b)+(a%b==0?0:1);}
 
/*---------------Custom HashMap----------------------------------------------------------*/
struct custom_hash{static uint64_t splitmix64(uint64_t x){x+=0x9e3779b97f4a7c15;x=(x^(x>>30))* 0xbf58476d1ce4e5b9;
x=(x^(x>>27))* 0x94d049bb133111eb;return x^(x>>31);}size_t operator()(uint64_t x)const{
static const uint64_t FIXED_RANDOM=chrono::steady_clock::now().time_since_epoch().count();return splitmix64(x+FIXED_RANDOM);}};
/*unordered_map<ll,ll,custom_hash>uchm;*/

/*--Lazy Segment tree template--*/
template<class T, class U>
// T -> node, U->update.
struct Lsegtree
{
    vector<T>st;
    vector<U>lazy;
    ll n;
    T identity_element;
    U identity_update;
    Lsegtree(ll n, T identity_element, U identity_update)
    {
        this->n = n;
        this->identity_element = identity_element;
        this->identity_update = identity_update;
        st.assign(4*n,identity_element);
        lazy.assign(4*n, identity_update);
    }
    T combine(T l, T r)
    {
        // change this function as required.
        T ans = min(l,r);
        return ans;
    }
    void buildUtil(ll v, ll tl, ll tr, vector<T>&a)
    {
        if(tl == tr)
        {
            st[v] = a[tl];
            return;
        }
        ll tm = (tl + tr)>>1;
        buildUtil(2*v + 1, tl, tm,a);
        buildUtil(2*v + 2,tm+1,tr,a);
        st[v] = combine(st[2*v + 1], st[2*v + 2]);
    }
    // change the following 2 functions, and you're more or less done.
    T apply(T curr, U upd, ll tl, ll tr)
    {
        T ans = (tr-tl+1)*upd;
        return ans;
    }
    U combineUpdate(U old_upd, U new_upd, ll tl, ll tr)
    {
        U ans = old_upd+new_upd;
        return ans;
    }  

    void push_down(ll v, ll tl, ll tr)
    {
        if(lazy[v] == identity_update)return;
        st[v] = apply(st[v], lazy[v], tl, tr);
        if(2*v + 2 < 4*n)
        {
            ll tm = (tl + tr)>>1;
            lazy[2*v + 1] = combineUpdate(lazy[2*v+1], lazy[v], tl, tm);
            lazy[2*v + 2] = combineUpdate(lazy[2*v+2], lazy[v], tm+1,tr);            
        }
        lazy[v] = identity_update;
    }
    T queryUtil(ll v, ll tl, ll tr, ll l, ll r)
    {
        push_down(v,tl,tr);
        if(l > r)return identity_element;
        if(tr < l or tl > r)
        {
            return identity_element;
        }
        if(l <= tl and r >= tr)
        {
            return st[v];
        }
        ll tm = (tl + tr)>>1;
        return combine(queryUtil(2*v+1,tl,tm,l,r), queryUtil(2*v+2,tm+1,tr,l,r));
    }
 
    void updateUtil(ll v, ll tl, ll tr, ll l, ll r, U upd)
    {
        push_down(v,tl,tr); 
        if(tr < l or tl > r)return;
        if(tl >=l and tr <=r)
        {
            lazy[v] = combineUpdate(lazy[v],upd,tl,tr);
            push_down(v,tl,tr);
        }
        else
        {
            ll tm = (tl + tr)>>1;
            updateUtil(2*v+1,tl,tm,l,r,upd);
            updateUtil(2*v+2,tm+1,tr,l,r,upd);
            st[v] = combine(st[2*v + 1], st[2*v+2]);
        }
    }

    void build(vector<T>a)
    {
        assert(a.size() == n);
        buildUtil(0,0,n-1,a);
    }
    T query(ll l, ll r)
    {
        return queryUtil(0,0,n-1,l,r);
    }
    void update(ll l,ll r, U upd)
    {
        updateUtil(0,0,n-1,l,r,upd);
    }
};

void do_it()
{
    ll n; cin>>n; 
    vll v(n); cin>>v;
    mll mp1; //val->index
    loop(i,0,n,1)
    {
        mp1[v[i]]=i;
    }
    map<ll, pair<vll,set<ll>>>mp2;//index->vals_orders
    loop(i,0,n,1)
    {
        mp2[i].ff.pb(v[i]);
        mp2[i].ss.ins(v[i]);
    }

    ll q; cin>>q;
    set<ll>er;
    while(q--)
    {
        ll t; cin>>t;
        if(t==2)
        {
            ll x; cin>>x;
            ll indx=mp1[x];
            mp1.erase(x);
            mp2[indx].ss.erase(x);
            er.ins(x);
        }
        else if(t==1)
        {
            ll x,y; cin>>x>>y;
            ll indx=mp1[x];
            mp1[y]=indx;
            mp2[indx].ff.pb(y); mp2[indx].ss.ins(y);
            er.erase(y);
        }
    }
    // for(auto it : mp2)
    // {
    //     for(auto it2 : it.ss)
    //     {
    //         if(er.find(it2)==er.end())
    //         {
    //             cout<<it2<<" ";
    //         }
    //     }
    // }

    for(auto it : mp2)
    {
        pair<vll,set<ll>> ps=it.ss;
        for(auto it2 : ps.ff)
        {
            if(ps.ss.find(it2)!=ps.ss.end()) cout<<it2<<" ";
        }
    }
    cout<<endl;
}
int32_t main(int argc, char const *argv[]){
    rapido
        // #ifndef ONLINE_JUDGE
        //     freopen("input.txt","r",stdin);
        //     freopen("output.txt","w",stdout);
        // #endif
    //precompute

    ll kin=1; //cin>>kin;
    for(ll i=1; i<=kin ;i++){
         //cout<<"Case #"<<i<<":"<<" ";  
         do_it();
    }
    return 0;
}

提出情報

提出日時
問題 E - Insert or Erase
ユーザ onlycoding143
言語 C++ 20 (gcc 12.2)
得点 0
コード長 8766 Byte
結果 WA
実行時間 796 ms
メモリ 103096 KiB

コンパイルエラー

Main.cpp: In function ‘int32_t main(int, const char**)’:
Main.cpp:251:18: warning: unused parameter ‘argc’ [-Wunused-parameter]
  251 | int32_t main(int argc, char const *argv[]){
      |              ~~~~^~~~
Main.cpp:251:36: warning: unused parameter ‘argv’ [-Wunused-parameter]
  251 | int32_t main(int argc, char const *argv[]){
      |                        ~~~~~~~~~~~~^~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 475
結果
AC × 2
AC × 8
WA × 16
セット名 テストケース
Sample sample_01.txt, sample_02.txt
All min.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, sample_01.txt, sample_02.txt
ケース名 結果 実行時間 メモリ
min.txt AC 1 ms 3564 KiB
random_01.txt WA 796 ms 81860 KiB
random_02.txt WA 541 ms 44556 KiB
random_03.txt WA 560 ms 71452 KiB
random_04.txt WA 168 ms 18964 KiB
random_05.txt WA 720 ms 63820 KiB
random_06.txt WA 458 ms 31676 KiB
random_07.txt WA 603 ms 62532 KiB
random_08.txt WA 235 ms 29836 KiB
random_09.txt WA 649 ms 57708 KiB
random_10.txt AC 254 ms 27312 KiB
random_11.txt WA 525 ms 57820 KiB
random_12.txt AC 35 ms 7496 KiB
random_13.txt WA 648 ms 99280 KiB
random_14.txt WA 419 ms 63800 KiB
random_15.txt AC 447 ms 57724 KiB
random_16.txt WA 703 ms 100664 KiB
random_17.txt WA 431 ms 63864 KiB
random_18.txt AC 438 ms 57816 KiB
random_19.txt WA 192 ms 46992 KiB
random_20.txt WA 324 ms 103096 KiB
random_21.txt AC 228 ms 57704 KiB
sample_01.txt AC 1 ms 3564 KiB
sample_02.txt AC 1 ms 3496 KiB