#include <bits/stdc++.h>
#include "towers.h"
using namespace std;
#define pb push_back
#define st first
#define nd second
typedef long long ll;
typedef long double ld;
const ll I = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;
const int II = 2 * 1000 * 1000 * 1000;
const ll M = 1000LL * 1000LL * 1000LL + 7LL;
const int N = 1<<17;
int drz[2 * N], drz2[2 * N];
vector<int> mrg[2 * N];
int tab[N], ml[N], mr[N], cdi[N], tim[N];
set<int> cur;
set<int>::iterator it;
set<pair<int, int>> dif;
void DoT(int n)
{
drz2[N] = II;
for(int i = 1; i <= n; ++i)
{
drz[i + N] = tim[i]; drz2[i + N] = tim[i];
mrg[i + N] = {tim[i]};
}
for(int i = n + 1; i < N; ++i) drz2[i + N] = II;
for(int i = N - 1; i >= 1; --i)
{
drz[i] = max(drz[2 * i], drz[2 * i + 1]);
drz2[i] = min(drz2[2 * i], drz2[2 * i + 1]);
mrg[i] = mrg[i * 2];
for(int j = 0; j < (int)mrg[i * 2 + 1].size(); ++j)
mrg[i].pb(mrg[i * 2 + 1][j]);
sort(mrg[i].begin(), mrg[i].end());
}
}
inline int Il(int v, int x)
{
return (mrg[v].end() - lower_bound(mrg[v].begin(), mrg[v].end(), x));
}
int Query(int a, int b, int x)
{
a += N - 1; b += N + 1;
int ans = 0;
while(a / 2 != b / 2)
{
if(a % 2 == 0) ans += Il(a + 1, x);
if(b % 2 == 1) ans += Il(b - 1, x);
a /= 2; b /= 2;
}
return ans;
}
int GetL(int v)
{
it = cur.lower_bound(v);
if(it == cur.begin()) return 0;
--it; return *it;
}
int GetR(int v)
{
it = cur.upper_bound(v);
if(it == cur.end()) return 0;
return *it;
}
void init(int _N, vector<int> _H)
{
int n = _N;
for(int i = 1; i <= n; ++i) tab[i] = _H[i - 1];
for(int i = 1; i <= n; ++i)
{
ml[i] = 0LL; mr[i] = 0LL;
cur.insert(i);
}
ml[1] = II; mr[n] = II;
for(int i = 1; i <= n; ++i)
{
cdi[i] = min(ml[i], mr[i]) - tab[i];
dif.insert(make_pair(cdi[i], i));
}
while((int)cur.size() > 1)
{
int v = (*dif.begin()).nd;
dif.erase(dif.begin());
cur.erase(v);
tim[v] = cdi[v];
int l = GetL(v), r = GetR(v);
int xd = max(tab[v], max(mr[v], ml[v]));
if(l != 0)
{
dif.erase(make_pair(cdi[l], l));
mr[l] = max(mr[l], xd);
cdi[l] = min(ml[l], mr[l]) - tab[l];
dif.insert(make_pair(cdi[l], l));
}
if(r != 0)
{
dif.erase(make_pair(cdi[r], r));
ml[r] = max(ml[r], xd);
cdi[r] = min(ml[r], mr[r]) - tab[r];
dif.insert(make_pair(cdi[r], r));
}
}
tim[*cur.begin()] = II;
DoT(n);
//for(int i = 1; i <= n; ++i)
//cerr << tim[i] << " ";
//cerr << "\n";
}
int max_towers(int L, int R, int D)
{
int ans = Query(L + 1, R + 1, D);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
372 ms |
18352 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
10584 KB |
Output is correct |
2 |
Correct |
7 ms |
10968 KB |
Output is correct |
3 |
Correct |
5 ms |
11096 KB |
Output is correct |
4 |
Correct |
5 ms |
11096 KB |
Output is correct |
5 |
Correct |
5 ms |
11092 KB |
Output is correct |
6 |
Correct |
5 ms |
11096 KB |
Output is correct |
7 |
Incorrect |
6 ms |
11096 KB |
1st lines differ - on the 1st token, expected: '34', found: '33' |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
10584 KB |
Output is correct |
2 |
Correct |
7 ms |
10968 KB |
Output is correct |
3 |
Correct |
5 ms |
11096 KB |
Output is correct |
4 |
Correct |
5 ms |
11096 KB |
Output is correct |
5 |
Correct |
5 ms |
11092 KB |
Output is correct |
6 |
Correct |
5 ms |
11096 KB |
Output is correct |
7 |
Incorrect |
6 ms |
11096 KB |
1st lines differ - on the 1st token, expected: '34', found: '33' |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
760 ms |
23724 KB |
1st lines differ - on the 1st token, expected: '11903', found: '11902' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
239 ms |
13864 KB |
Output is correct |
2 |
Correct |
936 ms |
24004 KB |
Output is correct |
3 |
Correct |
988 ms |
24008 KB |
Output is correct |
4 |
Correct |
978 ms |
23900 KB |
Output is correct |
5 |
Correct |
964 ms |
24008 KB |
Output is correct |
6 |
Correct |
952 ms |
23492 KB |
Output is correct |
7 |
Correct |
1029 ms |
23240 KB |
Output is correct |
8 |
Correct |
802 ms |
23240 KB |
Output is correct |
9 |
Correct |
727 ms |
23192 KB |
Output is correct |
10 |
Correct |
813 ms |
23240 KB |
Output is correct |
11 |
Correct |
798 ms |
23496 KB |
Output is correct |
12 |
Correct |
241 ms |
23496 KB |
Output is correct |
13 |
Correct |
235 ms |
23792 KB |
Output is correct |
14 |
Correct |
232 ms |
24008 KB |
Output is correct |
15 |
Correct |
72 ms |
23496 KB |
Output is correct |
16 |
Correct |
100 ms |
23480 KB |
Output is correct |
17 |
Correct |
219 ms |
22988 KB |
Output is correct |
18 |
Correct |
248 ms |
23344 KB |
Output is correct |
19 |
Correct |
243 ms |
23924 KB |
Output is correct |
20 |
Correct |
232 ms |
24008 KB |
Output is correct |
21 |
Correct |
244 ms |
23252 KB |
Output is correct |
22 |
Correct |
240 ms |
23420 KB |
Output is correct |
23 |
Correct |
251 ms |
23240 KB |
Output is correct |
24 |
Correct |
80 ms |
23240 KB |
Output is correct |
25 |
Correct |
79 ms |
23240 KB |
Output is correct |
26 |
Correct |
103 ms |
23240 KB |
Output is correct |
27 |
Correct |
96 ms |
23240 KB |
Output is correct |
28 |
Correct |
6 ms |
8536 KB |
Output is correct |
29 |
Correct |
6 ms |
8536 KB |
Output is correct |
30 |
Correct |
6 ms |
8536 KB |
Output is correct |
31 |
Correct |
3 ms |
10840 KB |
Output is correct |
32 |
Correct |
4 ms |
10840 KB |
Output is correct |
33 |
Correct |
3 ms |
10840 KB |
Output is correct |
34 |
Correct |
6 ms |
11096 KB |
Output is correct |
35 |
Correct |
4 ms |
10968 KB |
Output is correct |
36 |
Correct |
5 ms |
11096 KB |
Output is correct |
37 |
Correct |
4 ms |
11096 KB |
Output is correct |
38 |
Correct |
5 ms |
11096 KB |
Output is correct |
39 |
Correct |
4 ms |
11096 KB |
Output is correct |
40 |
Correct |
3 ms |
10840 KB |
Output is correct |
41 |
Correct |
3 ms |
10840 KB |
Output is correct |
42 |
Correct |
5 ms |
10840 KB |
Output is correct |
43 |
Correct |
6 ms |
10840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
10584 KB |
Output is correct |
2 |
Correct |
7 ms |
10968 KB |
Output is correct |
3 |
Correct |
5 ms |
11096 KB |
Output is correct |
4 |
Correct |
5 ms |
11096 KB |
Output is correct |
5 |
Correct |
5 ms |
11092 KB |
Output is correct |
6 |
Correct |
5 ms |
11096 KB |
Output is correct |
7 |
Incorrect |
6 ms |
11096 KB |
1st lines differ - on the 1st token, expected: '34', found: '33' |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
372 ms |
18352 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |