# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
814250 |
2023-08-08T06:34:33 Z |
LIF |
송신탑 (IOI22_towers) |
C++17 |
|
4000 ms |
11664 KB |
#include "towers.h"
#include <vector>
#include <stack>
#include <bits/stdc++.h>
using namespace std;
int n;
pair <int,int> aa[300005];
int b[300005];
int rightD[300005];
int leftD[300005];
void init(int N, std::vector<int> H)
{
n = N;
for(int i=0;i<H.size();i++)
{
aa[i+1].first = H[i];
aa[i+1].second = i+1;
b[i+1] = H[i];
}
sort(aa+1,aa+n+1);
for(int i=N;i>=1;i--)
{
rightD[i] = N+1;
leftD[i] = 0;
}
return;
}
int lowbit(int x)
{
return x & (-x);
}
int su[300005];
void change(int x,int add)
{
while(x <= n)
{
su[x] += add;
x += lowbit(x);
}
}
int query(int x)
{
int ans = 0;
while(x > 0)
{
ans += su[x];
x -= lowbit(x);
}
return ans;
}
int ask(int l,int r)
{
return query(r) - query(l-1);
}
int st[200005][22];
int findmax(int l,int r)
{
if(l > r)return -1e9;
if(r <= 0 || l >= n+1)return -1e9;
int xx = log(r-l+1) / log(2);
return max(st[l][xx],st[r-(1<<xx)+1][xx]);
}
int max_towers(int L, int R, int D)
{
L += 1;R += 1;
for(int i=1;i<=n;i++)st[i][0] = b[i];
for(int i=1;i<=20;i++)
{
for(int j=1;j+(1<<i)-1 <= n;j++)
{
st[j][i] = max(st[j][i-1],st[j + (1<<(i-1))][i-1]);
// cout<<j<<" "<<i<<" "<<st[j][i]<<endl;
}
}
/*
for(int i=1;i<=n;i++)
{
for(int j=i+1;j<=n;j++)cout<<i<<" "<<j<<" "<<findmax(i,j)<<endl;
}*/
for(int i=1;i<=n;i++)
{
int l = 1;
int r = i-1;
int left = 0;
int right = n+1;
while(l<=r)
{
int mid = (l+r)>>1;
//cout<<l<<" "<<r<<" "<<findmax(mid,i-1)<<endl;
if(findmax(mid,i-1) >= b[i] + D)
{
left = mid;
l = mid + 1;
}
else r = mid - 1;
}
leftD[i] = left;
l = i+1;
r = n;
while(l <= r)
{
int mid = (l+r)>>1;
if(findmax(i+1,mid) >= b[i] + D)
{
right = mid;
r = mid - 1;
}
else l = mid + 1;
}
rightD[i] = right;
}
//cout<<endl;
//for(int i=1;i<=n;i++)cout<<leftD[i]<<" "<<rightD[i]<<endl;
int ans = 0;
for(int now=1;now<=n;now++)
{
int i = aa[now].second;
if(i < L || i > R)continue;
// cout<<i<<" ";
//if(leftD[i] < L || rightD[i] > R)continue;
if(ask(leftD[i],i) <= 0 && ask(i,rightD[i]) <= 0)
{
// cout<<i<<endl;
change(i,1);
ans++;
}
}
return ans;
}
Compilation message
towers.cpp: In function 'void init(int, std::vector<int>)':
towers.cpp:14:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | for(int i=0;i<H.size();i++)
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4089 ms |
6892 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
464 KB |
Output is correct |
3 |
Correct |
1 ms |
464 KB |
Output is correct |
4 |
Correct |
2 ms |
464 KB |
Output is correct |
5 |
Correct |
1 ms |
464 KB |
Output is correct |
6 |
Correct |
2 ms |
464 KB |
Output is correct |
7 |
Correct |
1 ms |
556 KB |
Output is correct |
8 |
Correct |
1 ms |
464 KB |
Output is correct |
9 |
Correct |
1 ms |
464 KB |
Output is correct |
10 |
Correct |
2 ms |
464 KB |
Output is correct |
11 |
Correct |
2 ms |
464 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
464 KB |
Output is correct |
14 |
Correct |
1 ms |
464 KB |
Output is correct |
15 |
Correct |
1 ms |
464 KB |
Output is correct |
16 |
Correct |
2 ms |
464 KB |
Output is correct |
17 |
Correct |
2 ms |
464 KB |
Output is correct |
18 |
Correct |
2 ms |
464 KB |
Output is correct |
19 |
Correct |
1 ms |
464 KB |
Output is correct |
20 |
Correct |
2 ms |
464 KB |
Output is correct |
21 |
Correct |
1 ms |
464 KB |
Output is correct |
22 |
Correct |
2 ms |
464 KB |
Output is correct |
23 |
Correct |
1 ms |
464 KB |
Output is correct |
24 |
Correct |
1 ms |
464 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
464 KB |
Output is correct |
27 |
Correct |
1 ms |
464 KB |
Output is correct |
28 |
Correct |
1 ms |
464 KB |
Output is correct |
29 |
Correct |
1 ms |
464 KB |
Output is correct |
30 |
Correct |
1 ms |
464 KB |
Output is correct |
31 |
Correct |
1 ms |
464 KB |
Output is correct |
32 |
Correct |
1 ms |
464 KB |
Output is correct |
33 |
Correct |
2 ms |
464 KB |
Output is correct |
34 |
Correct |
2 ms |
464 KB |
Output is correct |
35 |
Correct |
1 ms |
464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
464 KB |
Output is correct |
3 |
Correct |
1 ms |
464 KB |
Output is correct |
4 |
Correct |
2 ms |
464 KB |
Output is correct |
5 |
Correct |
1 ms |
464 KB |
Output is correct |
6 |
Correct |
2 ms |
464 KB |
Output is correct |
7 |
Correct |
1 ms |
556 KB |
Output is correct |
8 |
Correct |
1 ms |
464 KB |
Output is correct |
9 |
Correct |
1 ms |
464 KB |
Output is correct |
10 |
Correct |
2 ms |
464 KB |
Output is correct |
11 |
Correct |
2 ms |
464 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
464 KB |
Output is correct |
14 |
Correct |
1 ms |
464 KB |
Output is correct |
15 |
Correct |
1 ms |
464 KB |
Output is correct |
16 |
Correct |
2 ms |
464 KB |
Output is correct |
17 |
Correct |
2 ms |
464 KB |
Output is correct |
18 |
Correct |
2 ms |
464 KB |
Output is correct |
19 |
Correct |
1 ms |
464 KB |
Output is correct |
20 |
Correct |
2 ms |
464 KB |
Output is correct |
21 |
Correct |
1 ms |
464 KB |
Output is correct |
22 |
Correct |
2 ms |
464 KB |
Output is correct |
23 |
Correct |
1 ms |
464 KB |
Output is correct |
24 |
Correct |
1 ms |
464 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
464 KB |
Output is correct |
27 |
Correct |
1 ms |
464 KB |
Output is correct |
28 |
Correct |
1 ms |
464 KB |
Output is correct |
29 |
Correct |
1 ms |
464 KB |
Output is correct |
30 |
Correct |
1 ms |
464 KB |
Output is correct |
31 |
Correct |
1 ms |
464 KB |
Output is correct |
32 |
Correct |
1 ms |
464 KB |
Output is correct |
33 |
Correct |
2 ms |
464 KB |
Output is correct |
34 |
Correct |
2 ms |
464 KB |
Output is correct |
35 |
Correct |
1 ms |
464 KB |
Output is correct |
36 |
Correct |
44 ms |
7444 KB |
Output is correct |
37 |
Correct |
99 ms |
11400 KB |
Output is correct |
38 |
Correct |
82 ms |
11268 KB |
Output is correct |
39 |
Correct |
61 ms |
11396 KB |
Output is correct |
40 |
Correct |
76 ms |
11264 KB |
Output is correct |
41 |
Correct |
79 ms |
11520 KB |
Output is correct |
42 |
Correct |
88 ms |
11268 KB |
Output is correct |
43 |
Correct |
67 ms |
11272 KB |
Output is correct |
44 |
Correct |
58 ms |
11272 KB |
Output is correct |
45 |
Correct |
56 ms |
11276 KB |
Output is correct |
46 |
Correct |
59 ms |
11268 KB |
Output is correct |
47 |
Correct |
68 ms |
11360 KB |
Output is correct |
48 |
Correct |
64 ms |
11268 KB |
Output is correct |
49 |
Correct |
71 ms |
11300 KB |
Output is correct |
50 |
Correct |
61 ms |
11272 KB |
Output is correct |
51 |
Correct |
65 ms |
11304 KB |
Output is correct |
52 |
Correct |
109 ms |
11652 KB |
Output is correct |
53 |
Correct |
76 ms |
11656 KB |
Output is correct |
54 |
Correct |
87 ms |
11652 KB |
Output is correct |
55 |
Correct |
74 ms |
11264 KB |
Output is correct |
56 |
Correct |
65 ms |
11308 KB |
Output is correct |
57 |
Correct |
95 ms |
11168 KB |
Output is correct |
58 |
Correct |
101 ms |
11652 KB |
Output is correct |
59 |
Correct |
86 ms |
11648 KB |
Output is correct |
60 |
Correct |
88 ms |
11660 KB |
Output is correct |
61 |
Correct |
78 ms |
11660 KB |
Output is correct |
62 |
Correct |
82 ms |
11648 KB |
Output is correct |
63 |
Correct |
76 ms |
11664 KB |
Output is correct |
64 |
Correct |
77 ms |
11288 KB |
Output is correct |
65 |
Correct |
73 ms |
11268 KB |
Output is correct |
66 |
Correct |
68 ms |
11276 KB |
Output is correct |
67 |
Correct |
69 ms |
11272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4073 ms |
11600 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4088 ms |
3096 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
464 KB |
Output is correct |
3 |
Correct |
1 ms |
464 KB |
Output is correct |
4 |
Correct |
2 ms |
464 KB |
Output is correct |
5 |
Correct |
1 ms |
464 KB |
Output is correct |
6 |
Correct |
2 ms |
464 KB |
Output is correct |
7 |
Correct |
1 ms |
556 KB |
Output is correct |
8 |
Correct |
1 ms |
464 KB |
Output is correct |
9 |
Correct |
1 ms |
464 KB |
Output is correct |
10 |
Correct |
2 ms |
464 KB |
Output is correct |
11 |
Correct |
2 ms |
464 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
464 KB |
Output is correct |
14 |
Correct |
1 ms |
464 KB |
Output is correct |
15 |
Correct |
1 ms |
464 KB |
Output is correct |
16 |
Correct |
2 ms |
464 KB |
Output is correct |
17 |
Correct |
2 ms |
464 KB |
Output is correct |
18 |
Correct |
2 ms |
464 KB |
Output is correct |
19 |
Correct |
1 ms |
464 KB |
Output is correct |
20 |
Correct |
2 ms |
464 KB |
Output is correct |
21 |
Correct |
1 ms |
464 KB |
Output is correct |
22 |
Correct |
2 ms |
464 KB |
Output is correct |
23 |
Correct |
1 ms |
464 KB |
Output is correct |
24 |
Correct |
1 ms |
464 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
464 KB |
Output is correct |
27 |
Correct |
1 ms |
464 KB |
Output is correct |
28 |
Correct |
1 ms |
464 KB |
Output is correct |
29 |
Correct |
1 ms |
464 KB |
Output is correct |
30 |
Correct |
1 ms |
464 KB |
Output is correct |
31 |
Correct |
1 ms |
464 KB |
Output is correct |
32 |
Correct |
1 ms |
464 KB |
Output is correct |
33 |
Correct |
2 ms |
464 KB |
Output is correct |
34 |
Correct |
2 ms |
464 KB |
Output is correct |
35 |
Correct |
1 ms |
464 KB |
Output is correct |
36 |
Correct |
44 ms |
7444 KB |
Output is correct |
37 |
Correct |
99 ms |
11400 KB |
Output is correct |
38 |
Correct |
82 ms |
11268 KB |
Output is correct |
39 |
Correct |
61 ms |
11396 KB |
Output is correct |
40 |
Correct |
76 ms |
11264 KB |
Output is correct |
41 |
Correct |
79 ms |
11520 KB |
Output is correct |
42 |
Correct |
88 ms |
11268 KB |
Output is correct |
43 |
Correct |
67 ms |
11272 KB |
Output is correct |
44 |
Correct |
58 ms |
11272 KB |
Output is correct |
45 |
Correct |
56 ms |
11276 KB |
Output is correct |
46 |
Correct |
59 ms |
11268 KB |
Output is correct |
47 |
Correct |
68 ms |
11360 KB |
Output is correct |
48 |
Correct |
64 ms |
11268 KB |
Output is correct |
49 |
Correct |
71 ms |
11300 KB |
Output is correct |
50 |
Correct |
61 ms |
11272 KB |
Output is correct |
51 |
Correct |
65 ms |
11304 KB |
Output is correct |
52 |
Correct |
109 ms |
11652 KB |
Output is correct |
53 |
Correct |
76 ms |
11656 KB |
Output is correct |
54 |
Correct |
87 ms |
11652 KB |
Output is correct |
55 |
Correct |
74 ms |
11264 KB |
Output is correct |
56 |
Correct |
65 ms |
11308 KB |
Output is correct |
57 |
Correct |
95 ms |
11168 KB |
Output is correct |
58 |
Correct |
101 ms |
11652 KB |
Output is correct |
59 |
Correct |
86 ms |
11648 KB |
Output is correct |
60 |
Correct |
88 ms |
11660 KB |
Output is correct |
61 |
Correct |
78 ms |
11660 KB |
Output is correct |
62 |
Correct |
82 ms |
11648 KB |
Output is correct |
63 |
Correct |
76 ms |
11664 KB |
Output is correct |
64 |
Correct |
77 ms |
11288 KB |
Output is correct |
65 |
Correct |
73 ms |
11268 KB |
Output is correct |
66 |
Correct |
68 ms |
11276 KB |
Output is correct |
67 |
Correct |
69 ms |
11272 KB |
Output is correct |
68 |
Execution timed out |
4073 ms |
11600 KB |
Time limit exceeded |
69 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4089 ms |
6892 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |