結果
問題 | No.318 学学学学学 |
ユーザー | climpet |
提出日時 | 2015-12-12 02:51:33 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 18 ms / 2,000 ms |
コード長 | 3,711 bytes |
コンパイル時間 | 686 ms |
コンパイル使用メモリ | 75,464 KB |
実行使用メモリ | 7,296 KB |
最終ジャッジ日時 | 2024-06-22 15:50:07 |
合計ジャッジ時間 | 2,713 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 5 ms
7,040 KB |
testcase_01 | AC | 6 ms
7,168 KB |
testcase_02 | AC | 6 ms
7,168 KB |
testcase_03 | AC | 5 ms
7,040 KB |
testcase_04 | AC | 5 ms
7,168 KB |
testcase_05 | AC | 17 ms
7,168 KB |
testcase_06 | AC | 18 ms
7,168 KB |
testcase_07 | AC | 17 ms
7,168 KB |
testcase_08 | AC | 17 ms
7,296 KB |
testcase_09 | AC | 17 ms
7,168 KB |
testcase_10 | AC | 17 ms
7,296 KB |
testcase_11 | AC | 18 ms
7,168 KB |
testcase_12 | AC | 17 ms
7,296 KB |
testcase_13 | AC | 18 ms
7,296 KB |
testcase_14 | AC | 17 ms
7,168 KB |
testcase_15 | AC | 17 ms
7,168 KB |
testcase_16 | AC | 17 ms
7,040 KB |
testcase_17 | AC | 15 ms
7,168 KB |
testcase_18 | AC | 16 ms
7,168 KB |
testcase_19 | AC | 16 ms
7,168 KB |
testcase_20 | AC | 15 ms
7,168 KB |
testcase_21 | AC | 4 ms
7,168 KB |
testcase_22 | AC | 3 ms
7,040 KB |
testcase_23 | AC | 4 ms
7,168 KB |
testcase_24 | AC | 4 ms
7,168 KB |
testcase_25 | AC | 4 ms
7,168 KB |
testcase_26 | AC | 3 ms
7,168 KB |
testcase_27 | AC | 3 ms
7,168 KB |
testcase_28 | AC | 4 ms
7,040 KB |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:202:14: warning: ignoring return value of ‘ssize_t write(int, const void*, size_t)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 202 | write(1, buf, p - buf); | ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
#include <cstdio> #include <iostream> #include <vector> #include <set> #include <algorithm> #include <utility> #include <climits> #include <functional> #include <cstring> #include <numeric> #include <unistd.h> using namespace std; #define MAX_N 100010 typedef long long LL; typedef pair<int,int> pii; struct intset{ typedef unsigned long long ULL; vector<vector<ULL> > val; int n; intset() : n() {} explicit intset(int m){ init(m); } void init(int m){ n = m; val.clear(); do{ int t = (m + 63) >> 6; val.emplace_back(t); m = t; } while(m > 1); } bool contains(int x) const{ if(x < 0 || x >= n){ return false; } return val[0][x >> 6] >> (x & 63) & 1; } bool insert(int x){ if(x < 0 || x >= n){ return false; } if(contains(x)){ return false; } int h = val.size(); bool cont = true; for(int i = 0; cont && i < h; ++i){ int t = x >> 6; ULL &v = val[i][t]; cont = !v; v |= 1ull << (x & 63); x = t; } return true; } bool erase(int x){ if(x < 0 || x >= n){ return false; } if(!contains(x)){ return false; } int h = val.size(); bool cont = true; for(int i = 0; cont && i < h; ++i){ int t = x >> 6; ULL &v = val[i][t]; v &= ~(1ull << (x & 63)); cont = !v; x = t; } return true; } int successor(int x) const{ if(x >= n){ return INT_MAX; } if(x < 0){ if(contains(0)){ return 0; } x = 0; } int h = val.size(); int i; for(i = 0; i < h; ++i){ int t = x >> 6; ULL v = val[i][t]; v &= ~((2ull << (x & 63)) - 1); if(v){ x = (t << 6) + __builtin_ctzll(v); break; } x = t; } if(i == h){ return INT_MAX; } while(i > 0){ --i; x = (x << 6) + __builtin_ctzll(val[i][x]); } return x; } int predecessor(int x) const{ if(x <= 0){ return INT_MIN; } if(x >= n){ if(contains(n - 1)){ return n - 1; } x = n - 1; } int h = val.size(); int i; for(i = 0; i < h; ++i){ int t = x >> 6; ULL v = val[i][t]; v &= (1ull << (x & 63)) - 1; if(v){ x = (t << 6) + 63 - __builtin_clzll(v); break; } x = t; } if(i == h){ return INT_MIN; } while(i > 0){ --i; x = (x << 6) + 63 - __builtin_clzll(val[i][x]); } return x; } void swap(intset &other){ std::swap(n, other.n); val.swap(other.val); } }; struct hoge{ int fst, snd; }; int main(){ const int INF = 1010101010; char buf[1500000]; // int readsize = fread(buf, 1, sizeof buf, stdin); int readsize = read(0, buf, sizeof buf); buf[readsize] = 0; char *p = buf, *endp = 0; hoge a[MAX_N], tmp[MAX_N]; int b[MAX_N]; int cnt[32780] = {}; int n = strtol(p, &endp, 10); p = endp; for(int i = 0; i < n; ++i){ a[i].fst = strtol(p, &endp, 10); p = endp; a[i].snd = i; } for(int i = 0; i < n; ++i){ b[i] = 32767 - (a[i].fst & 32767); ++cnt[b[i] + 1]; } for(int i = 1; i < 32768; ++i){ cnt[i] += cnt[i - 1]; } for(int i = 0; i < n; ++i){ tmp[cnt[b[i]]++] = a[i]; } memset(cnt, 0, sizeof cnt); for(int i = 0; i < n; ++i){ b[i] = 32767 - (tmp[i].fst >> 15); ++cnt[b[i] + 1]; } for(int i = 1; i < 32768; ++i){ cnt[i] += cnt[i - 1]; } for(int i = 0; i < n; ++i){ a[cnt[b[i]]++] = tmp[i]; } a[n].fst = INF; intset is(n); for(int i = 0; i < n; ++i){ is.insert(i); } for(int i = 0; i < n; ){ int j; int val = a[i].fst; for(j = i + 1; a[j].fst == val; ++j); int l = a[i].snd - 1, r = a[j - 1].snd; while((l = is.successor(l)) <= r){ b[l] = val; is.erase(l); } i = j; } // for(int i = 0; i < n; ++i){ // printf("%d%c", b[i], i + 1 == n ? '\n' : ' '); // } p = buf; for(int i = 0; i < n; ++i){ p += sprintf(p, "%d ", b[i]); } p[-1] = '\n'; // fwrite(buf, 1, p - buf, stdout); write(1, buf, p - buf); }