Submission #60429


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <ios>
#include <iomanip>
#include <climits>
#include <functional>
using namespace std;
template< typename Monoid, typename OperatorMonoid = Monoid >
struct LazySegmentTree {
using F = function< Monoid(Monoid, Monoid) >;
using G = function< Monoid(Monoid, OperatorMonoid) >;
using H = function< OperatorMonoid(OperatorMonoid, OperatorMonoid) >;
int sz, height;
vector< Monoid > data;
vector< OperatorMonoid > lazy;
const F f;
const G g;
const H h;
const Monoid M1;
const OperatorMonoid OM0;
LazySegmentTree(int n, const F f, const G g, const H h,
const Monoid &M1, const OperatorMonoid OM0)
: f(f), g(g), h(h), M1(M1), OM0(OM0) {
sz = 1;
height = 0;
while(sz < n) sz <<= 1, height++;
data.assign(2 * sz, M1);
lazy.assign(2 * sz, OM0);
}
void set(int k, const Monoid &x) {
data[k + sz] = x;
}
void build() {
for(int k = sz - 1; k > 0; k--) {
data[k] = f(data[2 * k + 0], data[2 * k + 1]);
}
}
inline void propagate(int k) {
if(lazy[k] != OM0) {
lazy[2 * k + 0] = h(lazy[2 * k + 0], lazy[k]);
lazy[2 * k + 1] = h(lazy[2 * k + 1], lazy[k]);
data[k] = reflect(k);
lazy[k] = OM0;
}
}
inline Monoid reflect(int k) {
return lazy[k] == OM0 ? data[k] : g(data[k], lazy[k]);
}
inline void recalc(int k) {
while(k >>= 1) data[k] = f(reflect(2 * k + 0), reflect(2 * k + 1));
}
inline void thrust(int k) {
for(int i = height; i > 0; i--) propagate(k >> i);
}
void update(int a, int b, const OperatorMonoid &x) {
thrust(a += sz);
thrust(b += sz - 1);
for(int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
if(l & 1) lazy[l] = h(lazy[l], x), ++l;
if(r & 1) --r, lazy[r] = h(lazy[r], x);
}
recalc(a);
recalc(b);
}
Monoid query(int a, int b) {
thrust(a += sz);
thrust(b += sz - 1);
Monoid L = M1, R = M1;
for(int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
if(l & 1) L = f(L, reflect(l++));
if(r & 1) R = f(reflect(--r), R);
}
return f(L, R);
}
Monoid operator[](const int &k) {
return query(k, k + 1);
}
template< typename C >
int find_subtree(int a, const C &check, Monoid &M, bool type) {
while(a < sz) {
propagate(a);
Monoid nxt = type ? f(reflect(2 * a + type), M) : f(M, reflect(2 * a + type));
if(check(nxt)) a = 2 * a + type;
else M = nxt, a = 2 * a + 1 - type;
}
return a - sz;
}
template< typename C >
int find_first(int a, const C &check) {
Monoid L = M1;
if(a <= 0) {
if(check(f(L, reflect(1)))) return find_subtree(1, check, L, false);
return -1;
}
thrust(a + sz);
int b = sz;
for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
if(a & 1) {
Monoid nxt = f(L, reflect(a));
if(check(nxt)) return find_subtree(a, check, L, false);
L = nxt;
++a;
}
}
return -1;
}
template< typename C >
int find_last(int b, const C &check) {
Monoid R = M1;
if(b >= sz) {
if(check(f(reflect(1), R))) return find_subtree(1, check, R, true);
return -1;
}
thrust(b + sz - 1);
int a = sz;
for(b += sz; a < b; a >>= 1, b >>= 1) {
if(b & 1) {
Monoid nxt = f(reflect(--b), R);
if(check(nxt)) return find_subtree(b, check, R, true);
R = nxt;
}
}
return -1;
}
};
signed main()
{
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
int T;
cin >> T;
vector<tuple<int, int, int> > query;
vector<double> res(T);
for(int i = 0; i < T; ++i){
int L, K;
cin >> L >> K;
query.emplace_back(L, K, i);
}
sort(query.begin(), query.end());
int now_L = 0;
auto f = [](int a, int b){ return a + b; };
LazySegmentTree<int> seg(1000 * 1000 * 2 + 5, f, f, f, 0, 0);
for(auto&& [L, K, query_num] : query){
int minv = INT_MAX;
while(now_L <= L){
for(int i = 0; i < now_L; ++i){
seg.update(now_L * now_L + i * i, 1000 * 1000 * 2 + 1, 2);
}
seg.update(now_L * now_L * 2, 1000 * 1000 * 2 + 1, 1);
++now_L;
}
int ng = -1, ok = 1000 * 1000 * 2 + 1;
while(ok - ng > 1){
int mid = (ok + ng) / 2;
if(seg[mid] >= K){
ok = mid;
}else{
ng = mid;
}
}
res[query_num] = sqrt(ok);
}
for(auto&& e : res){
cout << fixed << setprecision(5) << e << '\n';
}
return (0);
}

ステータス

項目 データ
問題 1353 - Function of Euclidean Distance
ユーザー名 ei1903
投稿日時 2020-07-03 23:52:14
言語 C++17
状態 Accepted
得点 400
ソースコード長 4881 Byte
最大実行時間 490 ms
最大メモリ使用量 44920 KB

セット

セット 得点 Cases
1 task01 60 / 60 in01*, sample01.txt
2 task02 340 / 340 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
in01_01.txt AC 30 ms 33368 KB
1
2
in01_02.txt AC 264 ms 33440 KB
1
2
in01_03.txt AC 25 ms 33388 KB
1
2
in01_04.txt AC 262 ms 33340 KB
1
2
in01_05.txt AC 266 ms 33288 KB
1
2
in01_06.txt AC 28 ms 33236 KB
1
2
in01_07.txt AC 26 ms 33304 KB
1
2
in01_08.txt AC 34 ms 33380 KB
1
2
in01_09.txt AC 267 ms 33196 KB
1
2
in01_10.txt AC 258 ms 33400 KB
1
2
in02_01.txt AC 416 ms 36540 KB
2
in02_02.txt AC 422 ms 37584 KB
2
in02_03.txt AC 444 ms 38624 KB
2
in02_04.txt AC 389 ms 39416 KB
2
in02_05.txt AC 170 ms 40072 KB
2
in02_06.txt AC 490 ms 41120 KB
2
in02_07.txt AC 473 ms 42168 KB
2
in02_08.txt AC 475 ms 43088 KB
2
in02_09.txt AC 466 ms 44004 KB
2
in02_10.txt AC 480 ms 44920 KB
2
sample01.txt AC 31 ms 42908 KB
1
2
sample02.txt AC 258 ms 42852 KB
2