結果
問題 |
No.318 学学学学学
|
ユーザー |
![]() |
提出日時 | 2015-12-11 12:10:58 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 38 ms / 2,000 ms |
コード長 | 1,232 bytes |
コンパイル時間 | 786 ms |
コンパイル使用メモリ | 68,968 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-22 15:28:56 |
合計ジャッジ時間 | 3,137 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:41:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 41 | scanf("%d", &n); | ~~~~~^~~~~~~~~~ main.cpp:49:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 49 | scanf("%d", &x); | ~~~~~^~~~~~~~~~
ソースコード
#include <cstdio> #include <iostream> #include <vector> #include <set> #include <algorithm> #include <utility> #include <climits> #include <functional> using namespace std; #define MAX_N 100010 typedef long long LL; typedef pair<int,int> pii; int par[MAX_N]; int nxt[MAX_N]; int find(int x){ if(par[x] < 0){ return x; } return par[x] = find(par[x]); } void unite(int x, int y){ x = find(x); y = find(y); if(x == y){ return; } if(par[x] < par[y]){ swap(x, y); } par[y] += par[x]; par[x] = y; if(nxt[y] < nxt[x]){ nxt[y] = nxt[x]; } } LL a[MAX_N]; int b[MAX_N]; int main(){ const int INF = 1010101010; int n; scanf("%d", &n); for(int i = 0; i <= n; ++i){ par[i] = -1; nxt[i] = i + 1; } for(int i = 1; i <= n; ++i){ int x; scanf("%d", &x); a[i] = (LL)(INF - x) << 32 | i; } sort(a + 1, a + (n + 1)); a[n + 1] = LLONG_MAX; for(int i = 1; i <= n; ){ int j; int val = a[i] >> 32; for(j = i + 1; (a[j] >> 32) == val; ++j); val = INF - val; int l = a[i] & 0x7fffffff, r = a[j - 1] & 0x7fffffff; while(1){ int x = nxt[find(l - 1)]; if(x > r){ break; } b[x] = val; unite(l - 1, x); } i = j; } for(int i = 1; i <= n; ++i){ printf("%d%c", b[i], i == n ? '\n' : ' '); } }