# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
701568 |
2023-02-21T13:36:48 Z |
abysmal |
Fish 2 (JOI22_fish2) |
C++14 |
|
4000 ms |
4556 KB |
#include<iostream>
#include<stdio.h>
#include<stdint.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<string>
#include<assert.h>
#include<math.h>
#include<chrono>
#include<random>
#include<bitset>
#include<time.h>
#include<iomanip>
using namespace std;
const int64_t INF = (int64_t) 5 * 1e5 + 5;
const int64_t mINF = (int64_t) 1e9 + 5;
const int64_t MOD = (int64_t) 1e9 + 9;
const int nbit = 30;
const int ndig = 10;
const int nchar = 26;
const int p1 = 31;
const int p2 = 53;
const int D = 4;
int dr[D] = {0, 1, 0, -1};
int dc[D] = {1, 0, -1, 0};
// 0 right // 1 down // 2 left // 3 up
struct Solution
{
int n;
vector<int> a;
vector<int64_t> bit;
vector<int64_t> tree;
Solution() {}
void solve()
{
cin >> n;
a.resize(n, 0);
bit.resize(n + 1, 0);
for(int i = 0; i < n; i++)
{
int val;
cin >> val;
update(i + 1, val);
}
while(__builtin_popcount(n) != 1) n++;
tree.resize(2 * n, 0);
for(int i = 0; i < (int) a.size(); i++)
{
tree[n + i] = a[i];
}
for(int i = n - 1; i >= 1; i--)
{
tree[i] = max(tree[i * 2], tree[i * 2 + 1]);
}
int q;
cin >> q;
for(int i = 0; i < q; i++)
{
int t;
cin >> t;
if(t == 1)
{
int id;
int64_t x;
cin >> id >> x;
update(id, x);
updateTree(id - 1);
}
else
{
int l;
int r;
cin >> l >> r;
l--; r--;
int ans = 0;
for(int j = l; j <= r; j++)
{
if(check(j, l, r)) ans++;
}
cout << ans << "\n";
}
}
}
bool check(int id, int left, int right)
{
int x = id;
int y = id;
int64_t tmp = a[id];
while(x != left || y != right)
{
int l = left;
int r = x;
int i = x;
while(l <= r)
{
int mid = l + (r - l) / 2;
int64_t max_ = get(1, 0, n - 1, mid, x);
if(max_ <= tmp)
{
i = mid;
r = mid - 1;
}
else l = mid + 1;
}
tmp += sum(x) - sum(i);
l = y;
r = right;
int j = y;
while(l <= r)
{
int mid = l + (r - l) / 2;
int64_t max_ = get(1, 0, n - 1, y, mid);
if(max_ <= tmp)
{
j = mid;
l = mid + 1;
}
else r = mid - 1;
}
tmp += sum(j + 1) - sum(y + 1);
if(x == i && y == j) break;
x = i; y = j;
}
return (x == left && y == right);
}
int64_t sum(int i)
{
int64_t ans = 0;
while(i > 0)
{
ans += bit[i];
i -= (i & (-i));
}
return ans;
}
int64_t get(int node, int nleft, int nright, int left, int right)
{
if(nleft > right || nright < left) return 0;
if(left <= nleft && nright <= right) return tree[node];
int mid = nleft + (nright - nleft) / 2;
return max(get(node * 2, nleft, mid, left, right),
get(node * 2 + 1, mid + 1, nright, left, right));
}
void updateTree(int i)
{
tree[n + i] = a[i];
for(int j = (n + i) / 2; j >= 1; j /= 2)
{
tree[j] = max(tree[j * 2], tree[j * 2 + 1]);
}
}
void update(int i, int64_t val)
{
int64_t tmp = val - a[i - 1];
a[i - 1] = val;
while(i < (int) bit.size())
{
bit[i] += tmp;
i += (i & (-i));
}
}
int modsub(int t1, int t2)
{
int res = t1 - t2;
if(res < 0) res += MOD;
return res;
}
int modadd(int t1, int t2)
{
int res = t1 + t2;
if(res >= MOD) res -= MOD;
return res;
}
int modmul(int t1, int t2)
{
int64_t res = 1LL * t1 * t2;
return (res % MOD);
}
bool BIT(int mask, int j)
{
return (mask & MASK(j));
}
int64_t MASK(int j)
{
return (1LL << j);
}
int64_t Abs(int64_t t1)
{
if(t1 < 0) return -t1;
return t1;
}
};
void __startup()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
}
int main()
{
__startup();
int t = 1;
// cin >> t;
for(int i = 1; i <= t; i++)
{
Solution().solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
94 ms |
312 KB |
Output is correct |
6 |
Correct |
175 ms |
212 KB |
Output is correct |
7 |
Correct |
50 ms |
212 KB |
Output is correct |
8 |
Correct |
109 ms |
332 KB |
Output is correct |
9 |
Correct |
286 ms |
320 KB |
Output is correct |
10 |
Correct |
55 ms |
340 KB |
Output is correct |
11 |
Correct |
139 ms |
340 KB |
Output is correct |
12 |
Correct |
37 ms |
340 KB |
Output is correct |
13 |
Correct |
165 ms |
320 KB |
Output is correct |
14 |
Correct |
75 ms |
340 KB |
Output is correct |
15 |
Correct |
79 ms |
320 KB |
Output is correct |
16 |
Correct |
293 ms |
320 KB |
Output is correct |
17 |
Correct |
65 ms |
212 KB |
Output is correct |
18 |
Correct |
184 ms |
320 KB |
Output is correct |
19 |
Correct |
59 ms |
328 KB |
Output is correct |
20 |
Correct |
444 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
826 ms |
3568 KB |
Output is correct |
3 |
Correct |
806 ms |
3884 KB |
Output is correct |
4 |
Correct |
797 ms |
4144 KB |
Output is correct |
5 |
Correct |
831 ms |
3884 KB |
Output is correct |
6 |
Correct |
709 ms |
4428 KB |
Output is correct |
7 |
Correct |
1803 ms |
3756 KB |
Output is correct |
8 |
Correct |
722 ms |
4556 KB |
Output is correct |
9 |
Correct |
1640 ms |
3752 KB |
Output is correct |
10 |
Correct |
973 ms |
4128 KB |
Output is correct |
11 |
Correct |
830 ms |
3844 KB |
Output is correct |
12 |
Correct |
925 ms |
3800 KB |
Output is correct |
13 |
Correct |
952 ms |
3796 KB |
Output is correct |
14 |
Correct |
679 ms |
4172 KB |
Output is correct |
15 |
Correct |
736 ms |
4148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
94 ms |
312 KB |
Output is correct |
6 |
Correct |
175 ms |
212 KB |
Output is correct |
7 |
Correct |
50 ms |
212 KB |
Output is correct |
8 |
Correct |
109 ms |
332 KB |
Output is correct |
9 |
Correct |
286 ms |
320 KB |
Output is correct |
10 |
Correct |
55 ms |
340 KB |
Output is correct |
11 |
Correct |
139 ms |
340 KB |
Output is correct |
12 |
Correct |
37 ms |
340 KB |
Output is correct |
13 |
Correct |
165 ms |
320 KB |
Output is correct |
14 |
Correct |
75 ms |
340 KB |
Output is correct |
15 |
Correct |
79 ms |
320 KB |
Output is correct |
16 |
Correct |
293 ms |
320 KB |
Output is correct |
17 |
Correct |
65 ms |
212 KB |
Output is correct |
18 |
Correct |
184 ms |
320 KB |
Output is correct |
19 |
Correct |
59 ms |
328 KB |
Output is correct |
20 |
Correct |
444 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
826 ms |
3568 KB |
Output is correct |
23 |
Correct |
806 ms |
3884 KB |
Output is correct |
24 |
Correct |
797 ms |
4144 KB |
Output is correct |
25 |
Correct |
831 ms |
3884 KB |
Output is correct |
26 |
Correct |
709 ms |
4428 KB |
Output is correct |
27 |
Correct |
1803 ms |
3756 KB |
Output is correct |
28 |
Correct |
722 ms |
4556 KB |
Output is correct |
29 |
Correct |
1640 ms |
3752 KB |
Output is correct |
30 |
Correct |
973 ms |
4128 KB |
Output is correct |
31 |
Correct |
830 ms |
3844 KB |
Output is correct |
32 |
Correct |
925 ms |
3800 KB |
Output is correct |
33 |
Correct |
952 ms |
3796 KB |
Output is correct |
34 |
Correct |
679 ms |
4172 KB |
Output is correct |
35 |
Correct |
736 ms |
4148 KB |
Output is correct |
36 |
Execution timed out |
4030 ms |
4052 KB |
Time limit exceeded |
37 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
826 ms |
3568 KB |
Output is correct |
3 |
Correct |
806 ms |
3884 KB |
Output is correct |
4 |
Correct |
797 ms |
4144 KB |
Output is correct |
5 |
Correct |
831 ms |
3884 KB |
Output is correct |
6 |
Correct |
709 ms |
4428 KB |
Output is correct |
7 |
Correct |
1803 ms |
3756 KB |
Output is correct |
8 |
Correct |
722 ms |
4556 KB |
Output is correct |
9 |
Correct |
1640 ms |
3752 KB |
Output is correct |
10 |
Correct |
973 ms |
4128 KB |
Output is correct |
11 |
Correct |
830 ms |
3844 KB |
Output is correct |
12 |
Correct |
925 ms |
3800 KB |
Output is correct |
13 |
Correct |
952 ms |
3796 KB |
Output is correct |
14 |
Correct |
679 ms |
4172 KB |
Output is correct |
15 |
Correct |
736 ms |
4148 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Execution timed out |
4054 ms |
4048 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
826 ms |
3568 KB |
Output is correct |
3 |
Correct |
806 ms |
3884 KB |
Output is correct |
4 |
Correct |
797 ms |
4144 KB |
Output is correct |
5 |
Correct |
831 ms |
3884 KB |
Output is correct |
6 |
Correct |
709 ms |
4428 KB |
Output is correct |
7 |
Correct |
1803 ms |
3756 KB |
Output is correct |
8 |
Correct |
722 ms |
4556 KB |
Output is correct |
9 |
Correct |
1640 ms |
3752 KB |
Output is correct |
10 |
Correct |
973 ms |
4128 KB |
Output is correct |
11 |
Correct |
830 ms |
3844 KB |
Output is correct |
12 |
Correct |
925 ms |
3800 KB |
Output is correct |
13 |
Correct |
952 ms |
3796 KB |
Output is correct |
14 |
Correct |
679 ms |
4172 KB |
Output is correct |
15 |
Correct |
736 ms |
4148 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Execution timed out |
4058 ms |
4292 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
94 ms |
312 KB |
Output is correct |
6 |
Correct |
175 ms |
212 KB |
Output is correct |
7 |
Correct |
50 ms |
212 KB |
Output is correct |
8 |
Correct |
109 ms |
332 KB |
Output is correct |
9 |
Correct |
286 ms |
320 KB |
Output is correct |
10 |
Correct |
55 ms |
340 KB |
Output is correct |
11 |
Correct |
139 ms |
340 KB |
Output is correct |
12 |
Correct |
37 ms |
340 KB |
Output is correct |
13 |
Correct |
165 ms |
320 KB |
Output is correct |
14 |
Correct |
75 ms |
340 KB |
Output is correct |
15 |
Correct |
79 ms |
320 KB |
Output is correct |
16 |
Correct |
293 ms |
320 KB |
Output is correct |
17 |
Correct |
65 ms |
212 KB |
Output is correct |
18 |
Correct |
184 ms |
320 KB |
Output is correct |
19 |
Correct |
59 ms |
328 KB |
Output is correct |
20 |
Correct |
444 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
826 ms |
3568 KB |
Output is correct |
23 |
Correct |
806 ms |
3884 KB |
Output is correct |
24 |
Correct |
797 ms |
4144 KB |
Output is correct |
25 |
Correct |
831 ms |
3884 KB |
Output is correct |
26 |
Correct |
709 ms |
4428 KB |
Output is correct |
27 |
Correct |
1803 ms |
3756 KB |
Output is correct |
28 |
Correct |
722 ms |
4556 KB |
Output is correct |
29 |
Correct |
1640 ms |
3752 KB |
Output is correct |
30 |
Correct |
973 ms |
4128 KB |
Output is correct |
31 |
Correct |
830 ms |
3844 KB |
Output is correct |
32 |
Correct |
925 ms |
3800 KB |
Output is correct |
33 |
Correct |
952 ms |
3796 KB |
Output is correct |
34 |
Correct |
679 ms |
4172 KB |
Output is correct |
35 |
Correct |
736 ms |
4148 KB |
Output is correct |
36 |
Execution timed out |
4030 ms |
4052 KB |
Time limit exceeded |
37 |
Halted |
0 ms |
0 KB |
- |