답안 #939545

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
939545 2024-03-06T13:41:58 Z andrei_boaca Fish 2 (JOI22_fish2) C++17
25 / 100
4000 ms 4028 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
ll n,v[100005],q,s[100005],mars[100005];
int solve(int l,int r)
{
    s[l-1]=0;
    mars[l-1]=0;
    for(int i=l;i<=r;i++)
    {
        s[i]=s[i-1]+v[i];
        mars[i]=0;
    }
    stack<int> coada;
    for(int i=l;i<=r;i++)
    {
        while(!coada.empty()&&v[coada.top()]<v[i])
            coada.pop();
        int st=l-1;
        if(!coada.empty())
            st=coada.top();
        if(s[i-1]-s[st]<v[i])
        {
            mars[st+1]++;
            mars[i]--;
        }
        coada.push(i);
    }
    while(!coada.empty())
        coada.pop();
    for(int i=r;i>=l;i--)
    {
        while(!coada.empty()&&v[coada.top()]<v[i])
            coada.pop();
        int dr=r+1;
        if(!coada.empty())
            dr=coada.top();
        if(s[dr-1]-s[i]<v[i])
        {
            mars[i+1]++;
            mars[dr]--;
        }
        coada.push(i);
    }
    int ans=0;
    for(int i=l;i<=r;i++)
    {
        mars[i]+=mars[i-1];
        if(mars[i]==0)
            ans++;
    }
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>v[i];
    cin>>q;
    while(q--)
    {
        int tip;
        cin>>tip;
        if(tip==1)
        {
            int poz,val;
            cin>>poz>>val;
            v[poz]=val;
        }
        else
        {
            int l,r;
            cin>>l>>r;
            cout<<solve(l,r)<<'\n';
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2516 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 2 ms 2396 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 2 ms 2392 KB Output is correct
9 Correct 2 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 3 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 2 ms 2396 KB Output is correct
14 Correct 2 ms 2396 KB Output is correct
15 Correct 2 ms 2512 KB Output is correct
16 Correct 2 ms 2392 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 2 ms 2396 KB Output is correct
19 Correct 2 ms 2396 KB Output is correct
20 Correct 3 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 9 ms 3164 KB Output is correct
3 Correct 7 ms 2908 KB Output is correct
4 Correct 8 ms 3164 KB Output is correct
5 Correct 7 ms 2908 KB Output is correct
6 Correct 11 ms 3676 KB Output is correct
7 Correct 7 ms 3132 KB Output is correct
8 Correct 11 ms 3676 KB Output is correct
9 Correct 8 ms 2908 KB Output is correct
10 Correct 9 ms 3164 KB Output is correct
11 Correct 7 ms 3044 KB Output is correct
12 Correct 8 ms 3284 KB Output is correct
13 Correct 8 ms 2908 KB Output is correct
14 Correct 8 ms 3420 KB Output is correct
15 Correct 9 ms 3268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2516 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 2 ms 2396 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 2 ms 2392 KB Output is correct
9 Correct 2 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 3 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 2 ms 2396 KB Output is correct
14 Correct 2 ms 2396 KB Output is correct
15 Correct 2 ms 2512 KB Output is correct
16 Correct 2 ms 2392 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 2 ms 2396 KB Output is correct
19 Correct 2 ms 2396 KB Output is correct
20 Correct 3 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 9 ms 3164 KB Output is correct
23 Correct 7 ms 2908 KB Output is correct
24 Correct 8 ms 3164 KB Output is correct
25 Correct 7 ms 2908 KB Output is correct
26 Correct 11 ms 3676 KB Output is correct
27 Correct 7 ms 3132 KB Output is correct
28 Correct 11 ms 3676 KB Output is correct
29 Correct 8 ms 2908 KB Output is correct
30 Correct 9 ms 3164 KB Output is correct
31 Correct 7 ms 3044 KB Output is correct
32 Correct 8 ms 3284 KB Output is correct
33 Correct 8 ms 2908 KB Output is correct
34 Correct 8 ms 3420 KB Output is correct
35 Correct 9 ms 3268 KB Output is correct
36 Correct 220 ms 3384 KB Output is correct
37 Correct 365 ms 3132 KB Output is correct
38 Correct 430 ms 3132 KB Output is correct
39 Correct 100 ms 3376 KB Output is correct
40 Correct 473 ms 3140 KB Output is correct
41 Correct 635 ms 4028 KB Output is correct
42 Correct 808 ms 3696 KB Output is correct
43 Correct 671 ms 2908 KB Output is correct
44 Correct 778 ms 3156 KB Output is correct
45 Correct 259 ms 3668 KB Output is correct
46 Correct 352 ms 3368 KB Output is correct
47 Correct 512 ms 3072 KB Output is correct
48 Correct 243 ms 2908 KB Output is correct
49 Correct 820 ms 3156 KB Output is correct
50 Correct 359 ms 3420 KB Output is correct
51 Correct 1704 ms 3672 KB Output is correct
52 Correct 1715 ms 3428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 9 ms 3164 KB Output is correct
3 Correct 7 ms 2908 KB Output is correct
4 Correct 8 ms 3164 KB Output is correct
5 Correct 7 ms 2908 KB Output is correct
6 Correct 11 ms 3676 KB Output is correct
7 Correct 7 ms 3132 KB Output is correct
8 Correct 11 ms 3676 KB Output is correct
9 Correct 8 ms 2908 KB Output is correct
10 Correct 9 ms 3164 KB Output is correct
11 Correct 7 ms 3044 KB Output is correct
12 Correct 8 ms 3284 KB Output is correct
13 Correct 8 ms 2908 KB Output is correct
14 Correct 8 ms 3420 KB Output is correct
15 Correct 9 ms 3268 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Execution timed out 4050 ms 3536 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 9 ms 3164 KB Output is correct
3 Correct 7 ms 2908 KB Output is correct
4 Correct 8 ms 3164 KB Output is correct
5 Correct 7 ms 2908 KB Output is correct
6 Correct 11 ms 3676 KB Output is correct
7 Correct 7 ms 3132 KB Output is correct
8 Correct 11 ms 3676 KB Output is correct
9 Correct 8 ms 2908 KB Output is correct
10 Correct 9 ms 3164 KB Output is correct
11 Correct 7 ms 3044 KB Output is correct
12 Correct 8 ms 3284 KB Output is correct
13 Correct 8 ms 2908 KB Output is correct
14 Correct 8 ms 3420 KB Output is correct
15 Correct 9 ms 3268 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Execution timed out 4045 ms 3792 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2516 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 2 ms 2396 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 2 ms 2392 KB Output is correct
9 Correct 2 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 3 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 2 ms 2396 KB Output is correct
14 Correct 2 ms 2396 KB Output is correct
15 Correct 2 ms 2512 KB Output is correct
16 Correct 2 ms 2392 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 2 ms 2396 KB Output is correct
19 Correct 2 ms 2396 KB Output is correct
20 Correct 3 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 9 ms 3164 KB Output is correct
23 Correct 7 ms 2908 KB Output is correct
24 Correct 8 ms 3164 KB Output is correct
25 Correct 7 ms 2908 KB Output is correct
26 Correct 11 ms 3676 KB Output is correct
27 Correct 7 ms 3132 KB Output is correct
28 Correct 11 ms 3676 KB Output is correct
29 Correct 8 ms 2908 KB Output is correct
30 Correct 9 ms 3164 KB Output is correct
31 Correct 7 ms 3044 KB Output is correct
32 Correct 8 ms 3284 KB Output is correct
33 Correct 8 ms 2908 KB Output is correct
34 Correct 8 ms 3420 KB Output is correct
35 Correct 9 ms 3268 KB Output is correct
36 Correct 220 ms 3384 KB Output is correct
37 Correct 365 ms 3132 KB Output is correct
38 Correct 430 ms 3132 KB Output is correct
39 Correct 100 ms 3376 KB Output is correct
40 Correct 473 ms 3140 KB Output is correct
41 Correct 635 ms 4028 KB Output is correct
42 Correct 808 ms 3696 KB Output is correct
43 Correct 671 ms 2908 KB Output is correct
44 Correct 778 ms 3156 KB Output is correct
45 Correct 259 ms 3668 KB Output is correct
46 Correct 352 ms 3368 KB Output is correct
47 Correct 512 ms 3072 KB Output is correct
48 Correct 243 ms 2908 KB Output is correct
49 Correct 820 ms 3156 KB Output is correct
50 Correct 359 ms 3420 KB Output is correct
51 Correct 1704 ms 3672 KB Output is correct
52 Correct 1715 ms 3428 KB Output is correct
53 Correct 1 ms 2652 KB Output is correct
54 Execution timed out 4050 ms 3536 KB Time limit exceeded
55 Halted 0 ms 0 KB -