結果
| 問題 |
No.8072 Sum of sqrt(x)
|
| ユーザー |
chocorusk
|
| 提出日時 | 2020-09-12 22:09:17 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
TLE
(最新)
OLE
(最初)
|
| 実行時間 | - |
| コード長 | 2,967 bytes |
| コンパイル時間 | 3,058 ms |
| コンパイル使用メモリ | 163,072 KB |
| 実行使用メモリ | 98,448 KB |
| 最終ジャッジ日時 | 2025-01-02 14:39:47 |
| 合計ジャッジ時間 | 80,086 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 4 TLE * 22 OLE * 1 |
ソースコード
#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;
template<typename Monoid, typename OperatorMonoid=Monoid>
struct LazySegmentTree{
using F=function<Monoid(Monoid, Monoid)>;
using G=function<Monoid(Monoid, OperatorMonoid, int)>;
using H=function<OperatorMonoid(OperatorMonoid, OperatorMonoid)>;
int sz;
vector<Monoid> data;
vector<OperatorMonoid> lazy;
const F f;
const G g;
const H h;
const Monoid e1;
const OperatorMonoid e0;
LazySegmentTree(int n, const F f, const G g, const H h, const Monoid &e1, const OperatorMonoid &e0): f(f), g(g), h(h), e1(e1), e0(e0){
sz=1;
while(sz<n) sz<<=1;
data.resize(2*sz-1, e1);
lazy.resize(2*sz-1, e0);
}
void build(vector<Monoid> v){
for(int i=0; i<v.size(); i++) data[i+sz-1]=v[i];
for(int i=sz-2; i>=0; i--) data[i]=f(data[2*i+1], data[2*i+2]);
}
void eval(int k, int l, int r){
if(lazy[k]!=e0){
data[k]=g(data[k], lazy[k], r-l);
if(k<sz-1){
lazy[2*k+1]=h(lazy[2*k+1], lazy[k]);
lazy[2*k+2]=h(lazy[2*k+2], lazy[k]);
}
}
lazy[k]=e0;
}
void update(int a, int b, const OperatorMonoid &x, int k, int l, int r){
eval(k, l, r);
if(r<=a || b<=l) return;
if(a<=l && r<=b){
lazy[k]=h(lazy[k], x);
eval(k, l, r);
}else{
update(a, b, x, 2*k+1, l, (l+r)/2);
update(a, b, x, 2*k+2, (l+r)/2, r);
data[k]=f(data[2*k+1], data[2*k+2]);
}
}
void update(int a, int b, const OperatorMonoid &x){
return update(a, b, x, 0, 0, sz);
}
Monoid find(int a, int b, int k, int l, int r){
eval(k, l, r);
if(b<=l || r<=a) return e1;
if(a<=l && r<=b) return data[k];
else return f(find(a, b, 2*k+1, l, (l+r)/2), find(a, b, 2*k+2, (l+r)/2, r));
}
Monoid find(int a, int b){
return find(a, b, 0, 0, sz);
}
Monoid operator[](const int &k){
return find(k, k+1);
}
};
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());
auto f=[](long double a, long double b){
return a+b;
};
auto g=[](long double a, long double x, int len){
return a+x*len;
};
auto h=[](long double a, long double b){
return a+b;
};
LazySegmentTree<long double> seg(n, f, g, h, 0.0L, 0.0L);
for(int i=0; i<n; i++){
seg.update(v[i].second, n, sqrt((long double)v[i].first));
}
for(int i=0; i<n; i++){
printf("%.17Lf\n", seg[i]);
}
return 0;
}
chocorusk