Submission #551534

#TimeUsernameProblemLanguageResultExecution timeMemory
551534PedroBigMan자리 배치 (IOI18_seats)C++14
17 / 100
4093 ms250096 KiB
/*
Author of all code: Pedro BIGMAN Dias
Last edit: 15/02/2021
*/
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <list>
#include <iomanip>
#include <stdlib.h>
#include <time.h>
#include <cstring>
#include "seats.h"
using namespace std;
typedef int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define REP(i,a,b) for(ll i=(ll) a; i<(ll) b; i++)
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define ff first
#define ss second
#define whole(x) x.begin(),x.end()
#define DEBUG(i) cout<<"Pedro Is The Master "<<i<<endl
#define INF 50000000
#define EPS 0.00000001
#define pi 3.14159
#define VV(vvvv,NNNN,xxxx); REP(i,0,NNNN) {vvvv.pb(xxxx);}
ll mod=1000000007LL;

template<class A=ll> 
void Out(vector<A> a) {REP(i,0,a.size()) {cout<<a[i]<<" ";} cout<<endl;}

template<class A=ll>
void In(vector<A> &a, ll N) {A cur; REP(i,0,N) {cin>>cur; a.pb(cur);}} 

class ST_max
{
    public:
    ll N;
    
    class SV //seg value
    {
        public:
        ll a; 
        SV() {a=0LL;}
        SV(ll x) {a=x;}
        
        SV operator & (SV X) {SV ANS(max(a,X.a)); return ANS;}
    };
    
    SV neuts; 
	
    SV upval(ll c) //how lazy values modify a seg value inside a node, c=current node
    {
        return p[c];
    }
    
    vector<SV> p;
    vector<pl> range;
    
    ST_max() {N=0LL;}
    ST_max(vector<ll> arr)
    {
        N = (ll) 1<<(ll) ceil(log2(arr.size()));
        REP(i,0,2*N) {range.pb(mp(0LL,0LL));}
        REP(i,0,N) {p.pb(neuts);}
        REP(i,0,arr.size()) {SV X(arr[i]); p.pb(X); range[i+N]=mp(i,i);}
        REP(i,arr.size(),N) {p.pb(neuts); range[i+N]=mp(i,i);}
        ll cur = N-1;
        while(cur>0)
        {
            p[cur]=p[2*cur]&p[2*cur+1];
            range[cur]=mp(range[2*cur].ff,range[2*cur+1].ss);
            cur--;
        }
	}
    
    SV query(ll a,ll b, ll c=1LL) //range [a,b], current node. initially: query(a,b)
    {
        ll x=range[c].ff; ll y=range[c].ss;
        if(y<a || x>b) {return neuts;}
        if(x>=a && y<=b) {return upval(c);}
        SV ans = query(a,b,2*c)&query(a,b,2*c+1);
        return ans;
    }
    
    void update(SV s, ll a, ll c=1LL) //update LV, range [a,b], current node, current range. initially: update(s,a,b)
    {
        ll x=range[c].ff; ll y=range[c].ss;
        if(y<a || x>a) {return ;}
        if(x==a && y==a) 
        {
            p[c]=s;
            return;
        }
        update(s,a,2*c); update(s,a,2*c+1);
        p[c]=upval(2*c)&upval(2*c+1);
    }
};

class ST_min
{
    public:
    ll N;
    
    class SV //seg value
    {
        public:
        ll a; 
        SV() {a=INF;}
        SV(ll x) {a=x;}
        
        SV operator & (SV X) {SV ANS(min(a,X.a)); return ANS;}
    };
    
    SV neuts; 
	
    SV upval(ll c) //how lazy values modify a seg value inside a node, c=current node
    {
        return p[c];
    }
    
    vector<SV> p;
    vector<pl> range;
    
    ST_min() {N=0LL;}
    ST_min(vector<ll> arr)
    {
        N = (ll) 1<<(ll) ceil(log2(arr.size()));
        REP(i,0,2*N) {range.pb(mp(0LL,0LL));}
        REP(i,0,N) {p.pb(neuts);}
        REP(i,0,arr.size()) {SV X(arr[i]); p.pb(X); range[i+N]=mp(i,i);}
        REP(i,arr.size(),N) {p.pb(neuts); range[i+N]=mp(i,i);}
        ll cur = N-1;
        while(cur>0)
        {
            p[cur]=p[2*cur]&p[2*cur+1];
            range[cur]=mp(range[2*cur].ff,range[2*cur+1].ss);
            cur--;
        }
	}
    
    SV query(ll a,ll b, ll c=1LL) //range [a,b], current node. initially: query(a,b)
    {
        ll x=range[c].ff; ll y=range[c].ss;
        if(y<a || x>b) {return neuts;}
        if(x>=a && y<=b) {return upval(c);}
        SV ans = query(a,b,2*c)&query(a,b,2*c+1);
        return ans;
    }
    
    void update(SV s, ll a, ll c=1LL) //update LV, range [a,b], current node, current range. initially: update(s,a,b)
    {
        ll x=range[c].ff; ll y=range[c].ss;
        if(y<a || x>a) {return ;}
        if(x==a && y==a) 
        {
            p[c]=s;
            return;
        }
        update(s,a,2*c); update(s,a,2*c+1);
        p[c]=upval(2*c)&upval(2*c+1);
    }
};

ll h,w,N;
ST_max H_max,W_max; ST_min H_min,W_min;
vector<ll> ans; ll t_ans;
vector<pl> p;

void give_initial_chart(int hh, int ww, vector<int> RR, vector<int> CC) 
{
 	h=hh; w=ww; N=h*w; 
	H_max=*(new ST_max(RR)); 
	H_min=*(new ST_min(RR)); 
	W_max=*(new ST_max(CC)); 
	W_min=*(new ST_min(CC)); 
	t_ans=0LL;
	REP(i,0,N)
	{
		p.pb({RR[i],CC[i]});
		if((H_max.query(0,i).a-H_min.query(0,i).a+1LL)*(W_max.query(0,i).a-W_min.query(0,i).a+1LL)==i+1LL) {ans.pb(1); t_ans++;} 
		else {ans.pb(0);}
	}
}

int swap_seats(int a, int b) 
{
	if(b<a) {swap(a,b);}
	pl pa = p[a];
	pl pb = p[b];
	swap(p[a],p[b]);
	H_max.update(pb.ff,a); H_min.update(pb.ff,a); W_max.update(pb.ss,a); W_min.update(pb.ss,a);
	H_max.update(pa.ff,b); H_min.update(pa.ff,b); W_max.update(pa.ss,b); W_min.update(pa.ss,b);
	ll newval,oldval; 
	ll h_max = H_max.query(0,a).a; ll h_min = H_min.query(0,a).a; ll w_max = W_max.query(0,a).a; ll w_min = W_min.query(0,a).a;
  	REP(i,a,b)
	{
		oldval=ans[i];
		h_max=max(h_max,p[i].ff); h_min=min(h_min,p[i].ff); w_max=max(w_max,p[i].ss); w_min=min(w_min,p[i].ss);
		if((h_max-h_min+1)*(w_max-w_min+1)==i+1) {newval=1;}
		else {newval=0;}
		ans[i]=newval; t_ans+=(newval-oldval);
	}
	return t_ans;
}

Compilation message (stderr)

seats.cpp:5: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    5 | #pragma GCC optimization ("O3")
      | 
seats.cpp:6: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    6 | #pragma GCC optimization ("unroll-loops")
      |
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...