제출 #1123354

#제출 시각아이디문제언어결과실행 시간메모리
1123354hainam2k9운세 보기 2 (JOI14_fortune_telling2)C++20
100 / 100
414 ms24272 KiB
#include <bits/stdc++.h> #define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0) #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout) #define ll long long #define ull unsigned long long #define i128 __int128 #define db long double #define sz(a) ((int)(a).size()) #define pb emplace_back #define pf emplace_front #define pob pop_back #define pof pop_front #define lb lower_bound #define ub upper_bound #define fi first #define se second #define ins emplace using namespace std; const int MOD = 1e9+7, MAXN = 2e5+5; const string NAME = ""; int n,k,val[MAXN][2],query[MAXN]; pair<int,int> p[MAXN]; set<pair<int,int>> s; ll rs=0; void compress(){ vector<int> v; for(int i = 1; i<=n; ++i) v.pb(p[i].fi), v.pb(p[i].se); for(int i = 1; i<=k; ++i) v.pb(query[i]); sort(v.begin(),v.end()), v.resize(unique(v.begin(),v.end())-v.begin()); for(int i = 1; i<=n; ++i){ p[i].fi=lb(v.begin(),v.end(),p[i].fi)-v.begin()+1; p[i].se=lb(v.begin(),v.end(),p[i].se)-v.begin()+1; } for(int i = 1; i<=k; ++i) query[i]=lb(v.begin(),v.end(),query[i])-v.begin()+1; } int sgtpos[MAXN*12]; void updatepos(int id, int l, int r, int pos, int val){ if(pos<l||r<pos) return; if(l==r){ sgtpos[id]=val; return; } int mid=(l+r)>>1; updatepos(id<<1,l,mid,pos,val); updatepos(id<<1|1,mid+1,r,pos,val); sgtpos[id]=max(sgtpos[id<<1],sgtpos[id<<1|1]); } int getpos(int id, int l, int r, int u, int v){ if(v<l||r<u||u>v) return 0; if(u<=l&&r<=v) return sgtpos[id]; int mid=(l+r)>>1; return max(getpos(id<<1,l,mid,u,v),getpos(id<<1|1,mid+1,r,u,v)); } int bit[MAXN*3]; void update(int pos, int val, int N){ while(pos<=N) bit[pos]+=val, pos+=pos&-pos; } int getsum(int pos){ int rs=0; while(pos>0) rs+=bit[pos], pos-=pos&-pos; return rs; } int main() { tt; if(fopen((NAME + ".INP").c_str(), "r")) fo; cin >> n >> k; for(int i = 1; i<=n; ++i) cin >> p[i].fi >> p[i].se, val[i][0]=p[i].fi, val[i][1]=p[i].se; for(int i = 1; i<=k; ++i) cin >> query[i]; compress(); int N=2*n+k; for(int i = 1; i<=k; ++i) updatepos(1,1,N,query[i],i); for(int i = 1; i<=n; ++i){ int MIN=min(p[i].fi,p[i].se),MAX=max(p[i].fi,p[i].se); s.ins(k-getpos(1,1,N,MIN,MAX-1)+1,i); } int j=1; for(pair<int,int> a : s){ while(j<a.fi) update(query[k+1-j++],1,N); int MAX=max(p[a.se].fi,p[a.se].se), larger=getsum(N)-getsum(MAX-1); if(a.fi<=k){ if(p[a.se].fi==MAX) rs+=val[a.se][larger&1]; else rs+=val[a.se][(larger&1)^1]; }else rs+=val[a.se][larger&1]; } cout << rs; }

컴파일 시 표준 에러 (stderr) 메시지

fortune_telling2.cpp: In function 'int main()':
fortune_telling2.cpp:3:19: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fortune_telling2.cpp:69:45: note: in expansion of macro 'fo'
   69 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
fortune_telling2.cpp:3:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |                                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fortune_telling2.cpp:69:45: note: in expansion of macro 'fo'
   69 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...