제출 #1083486

#제출 시각아이디문제언어결과실행 시간메모리
1083486lamlamlamPilot (NOI19_pilot)C++17
100 / 100
334 ms68076 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define endl '\n' const int MN = 1e6+5; int n,q,h[MN],y,ans[MN],pa[MN],sz[MN],res; vector<pair<int,int>> v; int papa(int x) { if(x==pa[x]) return x; return pa[x] = papa(pa[x]); } void uni_set(int u,int v) { int p1 = papa(u); int p2 = papa(v); if(p1==p2) return; //cout << "LOL\n"; if(sz[p1]<sz[p2]) swap(p1,p2); res += sz[p1]*sz[p2]; sz[p1] += sz[p2]; pa[p2] = p1; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #define task "sus" if(fopen(task".inp","r")){ freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } for(int i=0; i<MN; i++) pa[i] = i, sz[i] = 1; cin >> n >> q; for(int i=1; i<=n; i++) cin >> h[i],v.push_back({h[i],i}); sort(v.begin(),v.end()); int it = 0; for(int i=1; i<MN; i++){ while(it<n and v[it].first==i){ int val = v[it].first; int id = v[it].second; res++; if(id!=1 and val>=h[id-1]) uni_set(id,id-1); if(id!=n and val>=h[id+1]) uni_set(id,id+1); it++; } ans[i] = res; } while(q--){ cin >> y; cout << ans[y] << endl; } cerr << "\nTime: " << clock(); }

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

pilot.cpp: In function 'int main()':
pilot.cpp:31:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
pilot.cpp:32:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         freopen(task".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...