Submission #596860

# Submission time Handle Problem Language Result Execution time Memory
596860 2022-07-15T08:11:11 Z 조영욱(#8449) Fish 2 (JOI22_fish2) C++17
13 / 100
4000 ms 3292 KB
#include <bits/stdc++.h>
using namespace std;

int le[100001];
int ri[100001];
int arr[100001];
long long psum[100001];
int n;
int q;
typedef pair<int,int> P;
vector<P> vec;
bool win[100001];

int main(void) {
    scanf("%d",&n);
    for(int i=1;i<=n;i++) {
        scanf("%d",&arr[i]);
    }
    stack<int> s;
    for(int i=1;i<=n;i++) {
        psum[i]=psum[i-1]+arr[i];
        while (!s.empty()&&arr[s.top()]<=arr[i]) {
            s.pop();
        }
        if (s.empty()) {
            le[i]=-1;
        }
        else {
            le[i]=s.top();
        }
        s.push(i);
    }
    while (!s.empty()) {
        s.pop();
    }
    for(int i=n;i>0;i--) {
        vec.push_back(P(arr[i],i));
        while (!s.empty()&&arr[s.top()]<arr[i]) {
            s.pop();
        }
        if (s.empty()) {
            ri[i]=-1;
        }
        else {
            ri[i]=s.top();
        }
        s.push(i);
    }
    sort(vec.begin(),vec.end());
    reverse(vec.begin(),vec.end());
    scanf("%d",&q);
    for(int ind=0;ind<q;ind++) {
        int t,l,r;
        scanf("%d %d %d",&t,&l,&r);
        if (t==1) {
            vec.clear();
            arr[l]=r;
            stack<int> s;
            for(int i=1;i<=n;i++) {
                psum[i]=psum[i-1]+arr[i];
                while (!s.empty()&&arr[s.top()]<=arr[i]) {
                    s.pop();
                }
                if (s.empty()) {
                    le[i]=-1;
                }
                else {
                    le[i]=s.top();
                }
                s.push(i);
            }
            while (!s.empty()) {
                s.pop();
            }
            for(int i=n;i>0;i--) {
                vec.push_back(P(arr[i],i));
                while (!s.empty()&&arr[s.top()]<arr[i]) {
                    s.pop();
                }
                if (s.empty()) {
                    ri[i]=-1;
                }
                else {
                    ri[i]=s.top();
                }
                s.push(i);
            }
            sort(vec.begin(),vec.end());
            reverse(vec.begin(),vec.end());
        }
        else {
            int ret=0;
            for(int i=0;i<vec.size();i++) {
                int now=vec[i].second;
win[now]=false;
                if (now<l||now>r) {
                    continue;
                }
                if (le[now]!=-1&&le[now]>=l&&!win[le[now]]) {
                    continue;
                }
                if (ri[now]!=-1&&ri[now]<=r&&!win[ri[now]]) {
                    continue;
                }
                int lef=((le[now]==-1||le[now]<l)?l:le[now]+1);
                int rig=((ri[now]==-1||ri[now]>r)?r:ri[now]-1);
//if (ind==1) printf("%d %d\n",lef,rig);
                long long val=psum[rig]-psum[lef-1];
                if (lef==l&&rig==r) {
                    win[now]=true;
                    ret++;
                }
                else if (lef!=l&&arr[le[now]]<=val) {
                    win[now]=true;
                    ret++;
                }
                else if (rig!=r&&arr[ri[now]]<=val) {
                    win[now]=true;
                    ret++;
                }
            }
            printf("%d\n",ret);
        }
    }
}

Compilation message

fish2.cpp: In function 'int main()':
fish2.cpp:93:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |             for(int i=0;i<vec.size();i++) {
      |                         ~^~~~~~~~~~~
fish2.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
fish2.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         scanf("%d",&arr[i]);
      |         ~~~~~^~~~~~~~~~~~~~
fish2.cpp:51:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |     scanf("%d",&q);
      |     ~~~~~^~~~~~~~~
fish2.cpp:54:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |         scanf("%d %d %d",&t,&l,&r);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 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 12 ms 340 KB Output is correct
6 Correct 5 ms 340 KB Output is correct
7 Correct 15 ms 212 KB Output is correct
8 Correct 7 ms 340 KB Output is correct
9 Correct 5 ms 340 KB Output is correct
10 Correct 13 ms 336 KB Output is correct
11 Correct 4 ms 340 KB Output is correct
12 Correct 16 ms 340 KB Output is correct
13 Correct 5 ms 340 KB Output is correct
14 Correct 8 ms 340 KB Output is correct
15 Correct 11 ms 336 KB Output is correct
16 Correct 4 ms 340 KB Output is correct
17 Correct 14 ms 344 KB Output is correct
18 Correct 3 ms 340 KB Output is correct
19 Correct 12 ms 336 KB Output is correct
20 Correct 6 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 21 ms 3228 KB Output is correct
3 Correct 20 ms 3276 KB Output is correct
4 Correct 23 ms 3276 KB Output is correct
5 Correct 20 ms 3276 KB Output is correct
6 Correct 24 ms 3252 KB Output is correct
7 Correct 18 ms 3236 KB Output is correct
8 Correct 24 ms 3244 KB Output is correct
9 Correct 22 ms 3280 KB Output is correct
10 Correct 23 ms 3276 KB Output is correct
11 Correct 21 ms 3276 KB Output is correct
12 Correct 21 ms 3272 KB Output is correct
13 Correct 21 ms 3276 KB Output is correct
14 Correct 22 ms 3288 KB Output is correct
15 Correct 23 ms 3212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 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 12 ms 340 KB Output is correct
6 Correct 5 ms 340 KB Output is correct
7 Correct 15 ms 212 KB Output is correct
8 Correct 7 ms 340 KB Output is correct
9 Correct 5 ms 340 KB Output is correct
10 Correct 13 ms 336 KB Output is correct
11 Correct 4 ms 340 KB Output is correct
12 Correct 16 ms 340 KB Output is correct
13 Correct 5 ms 340 KB Output is correct
14 Correct 8 ms 340 KB Output is correct
15 Correct 11 ms 336 KB Output is correct
16 Correct 4 ms 340 KB Output is correct
17 Correct 14 ms 344 KB Output is correct
18 Correct 3 ms 340 KB Output is correct
19 Correct 12 ms 336 KB Output is correct
20 Correct 6 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 21 ms 3228 KB Output is correct
23 Correct 20 ms 3276 KB Output is correct
24 Correct 23 ms 3276 KB Output is correct
25 Correct 20 ms 3276 KB Output is correct
26 Correct 24 ms 3252 KB Output is correct
27 Correct 18 ms 3236 KB Output is correct
28 Correct 24 ms 3244 KB Output is correct
29 Correct 22 ms 3280 KB Output is correct
30 Correct 23 ms 3276 KB Output is correct
31 Correct 21 ms 3276 KB Output is correct
32 Correct 21 ms 3272 KB Output is correct
33 Correct 21 ms 3276 KB Output is correct
34 Correct 22 ms 3288 KB Output is correct
35 Correct 23 ms 3212 KB Output is correct
36 Execution timed out 4085 ms 3272 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 21 ms 3228 KB Output is correct
3 Correct 20 ms 3276 KB Output is correct
4 Correct 23 ms 3276 KB Output is correct
5 Correct 20 ms 3276 KB Output is correct
6 Correct 24 ms 3252 KB Output is correct
7 Correct 18 ms 3236 KB Output is correct
8 Correct 24 ms 3244 KB Output is correct
9 Correct 22 ms 3280 KB Output is correct
10 Correct 23 ms 3276 KB Output is correct
11 Correct 21 ms 3276 KB Output is correct
12 Correct 21 ms 3272 KB Output is correct
13 Correct 21 ms 3276 KB Output is correct
14 Correct 22 ms 3288 KB Output is correct
15 Correct 23 ms 3212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Execution timed out 4091 ms 3292 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 21 ms 3228 KB Output is correct
3 Correct 20 ms 3276 KB Output is correct
4 Correct 23 ms 3276 KB Output is correct
5 Correct 20 ms 3276 KB Output is correct
6 Correct 24 ms 3252 KB Output is correct
7 Correct 18 ms 3236 KB Output is correct
8 Correct 24 ms 3244 KB Output is correct
9 Correct 22 ms 3280 KB Output is correct
10 Correct 23 ms 3276 KB Output is correct
11 Correct 21 ms 3276 KB Output is correct
12 Correct 21 ms 3272 KB Output is correct
13 Correct 21 ms 3276 KB Output is correct
14 Correct 22 ms 3288 KB Output is correct
15 Correct 23 ms 3212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Execution timed out 4091 ms 3276 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 0 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 12 ms 340 KB Output is correct
6 Correct 5 ms 340 KB Output is correct
7 Correct 15 ms 212 KB Output is correct
8 Correct 7 ms 340 KB Output is correct
9 Correct 5 ms 340 KB Output is correct
10 Correct 13 ms 336 KB Output is correct
11 Correct 4 ms 340 KB Output is correct
12 Correct 16 ms 340 KB Output is correct
13 Correct 5 ms 340 KB Output is correct
14 Correct 8 ms 340 KB Output is correct
15 Correct 11 ms 336 KB Output is correct
16 Correct 4 ms 340 KB Output is correct
17 Correct 14 ms 344 KB Output is correct
18 Correct 3 ms 340 KB Output is correct
19 Correct 12 ms 336 KB Output is correct
20 Correct 6 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 21 ms 3228 KB Output is correct
23 Correct 20 ms 3276 KB Output is correct
24 Correct 23 ms 3276 KB Output is correct
25 Correct 20 ms 3276 KB Output is correct
26 Correct 24 ms 3252 KB Output is correct
27 Correct 18 ms 3236 KB Output is correct
28 Correct 24 ms 3244 KB Output is correct
29 Correct 22 ms 3280 KB Output is correct
30 Correct 23 ms 3276 KB Output is correct
31 Correct 21 ms 3276 KB Output is correct
32 Correct 21 ms 3272 KB Output is correct
33 Correct 21 ms 3276 KB Output is correct
34 Correct 22 ms 3288 KB Output is correct
35 Correct 23 ms 3212 KB Output is correct
36 Execution timed out 4085 ms 3272 KB Time limit exceeded
37 Halted 0 ms 0 KB -