結果
問題 |
No.8072 Sum of sqrt(x)
|
ユーザー |
![]() |
提出日時 | 2020-09-12 22:28:07 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,098 bytes |
コンパイル時間 | 2,621 ms |
コンパイル使用メモリ | 132,112 KB |
最終ジャッジ日時 | 2025-01-14 13:53:35 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 WA * 13 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:32:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 32 | scanf("%d", &n); | ~~~~~^~~~~~~~~~ main.cpp:36:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 36 | scanf("%lld", &x); | ~~~~~^~~~~~~~~~~~
ソースコード
#include <cstdio> #include <cstring> #include <iostream> #include <string> #include <cmath> #include <bitset> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> #include <complex> #include <unordered_map> #include <unordered_set> #include <random> #include <cassert> #include <fstream> #include <utility> #include <functional> #include <time.h> #include <stack> #include <array> #include <list> #define popcount __builtin_popcount using namespace std; typedef long long ll; typedef pair<int, int> P; int main() { int n; scanf("%d", &n); vector<pair<ll, int>> v(n); for(int i=0; i<n; i++){ ll x; scanf("%lld", &x); v[i]=make_pair(x, i); } sort(v.begin(), v.end()); long double seg[1<<21]={}; int sz=1; while(sz<n) sz<<=1; auto add=[&](int l, int r, long double x){ l+=sz, r+=sz; for(;l<r; l>>=1, r>>=1){ if(r&1) seg[--r]+=x; if(l&1) seg[l++]+=x; } }; auto calc=[&](int i){ i+=sz; long double ret=seg[i]; while(i>1){ i>>=1; ret+=seg[i]; } return ret; }; for(int i=0; i<n; i++){ add(v[i].second, n, sqrt((long double)v[i].first)); } for(int i=0; i<n; i++){ long double ans=calc(i); if(ans<1e1) printf("%.16Lf\n", ans); else if(ans<1e2) printf("%.15Lf\n", ans); else if(ans<1e3) printf("%.14Lf\n", ans); else if(ans<1e4) printf("%.13Lf\n", ans); else if(ans<1e5) printf("%.12Lf\n", ans); else if(ans<1e6) printf("%.11Lf\n", ans); else if(ans<1e7) printf("%.10Lf\n", ans); else if(ans<1e8) printf("%.9Lf\n", ans); else if(ans<1e9) printf("%.8Lf\n", ans); else if(ans<1e10) printf("%.7Lf\n", ans); else if(ans<1e11) printf("%.6Lf\n", ans); else if(ans<1e12) printf("%.5Lf\n", ans); else if(ans<1e13) printf("%.4Lf\n", ans); else if(ans<1e14) printf("%.3Lf\n", ans); else printf("%.2Lf\n", ans); } return 0; }