제출 #540529

#제출 시각아이디문제언어결과실행 시간메모리
540529PedroBigMan자리 배치 (IOI18_seats)C++14
0 / 100
4043 ms241348 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 500000000LL #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 b, 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>b) {return ;} if(x>=a && y<=b) { p[c]=s; return; } update(s,a,b,2*c); update(s,a,b,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 b, 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>b) {return ;} if(x>=a && y<=b) { p[c]=s; return; } update(s,a,b,2*c); update(s,a,b,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; void give_initial_chart(int hh, int ww, vector<int> RR, vector<int> CC) { h=hh; w=ww; N=h*w; ST_max HH_max(RR); H_max=HH_max; ST_min HH_min(RR); H_min=HH_min; ST_max WW_max(CC); W_max=WW_max; ST_min WW_min(CC); W_min=WW_min; t_ans=0LL; ll max_l,min_l,max_c,min_c; REP(i,0,N) { max_l=H_max.query(0,i).a; min_l=H_min.query(0,i).a; max_c=W_max.query(0,i).a; min_c=W_min.query(0,i).a; if((max_c-min_c)*(max_l-min_l)==i+1) {ans.pb(1); t_ans++;} else {ans.pb(0);} } } int swap_seats(int a, int b) { ll line_a = H_max.query(a,a).a; ll col_a = W_max.query(a,a).a; ll line_b = H_max.query(b,b).a; ll col_b = W_max.query(b,b).a; H_min.update(line_b,a,a); H_max.update(line_b,a,a); H_min.update(line_a,b,b); H_max.update(line_a,b,b); W_min.update(col_b,a,a); W_max.update(col_b,a,a); W_min.update(col_a,b,b); W_max.update(col_a,b,b); ll max_l,min_l,max_c,min_c; ll oldval,newval; REP(i,a,b+1) { max_l=H_max.query(0,i).a; min_l=H_min.query(0,i).a; max_c=W_max.query(0,i).a; min_c=W_min.query(0,i).a; oldval=ans[i]; if((max_c-min_c)*(max_l-min_l)==i+1) {newval=1;} else {newval=0;} ans[i]=newval; t_ans+=(newval-oldval); } return t_ans; }

컴파일 시 표준 에러 (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...