답안 #791846

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
791846 2023-07-24T10:59:44 Z eltu0815 Fish 2 (JOI22_fish2) C++14
25 / 100
4000 ms 8600 KB
#include <bits/stdc++.h>
#define MAX 500005
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define inf (1987654321)
 
using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
 
int n, q;
int arr[100005], l[100005], r[100005], ord[100005], chk[100005];
ll sum[100005];
pii tmp[100005];
vector<int> graph[100005];
 
void update_sum() {
    for(int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + arr[i];
}
 
void update_sort(int idx) {
    int j = 0, k = 0;
    for(int i = 1; i <= n; ++i) if(ord[i] == idx) j = i;
    for(int i = j; i < n; ++i) ord[i] = ord[i + 1];
    for(int i = 1; i < n; ++i) if(arr[ord[i]] >= arr[idx]) k = i;
    for(int i = n; i > k + 1; --i) ord[i] = ord[i - 1];
    ord[k + 1] = idx;
}
 
void update_r() {
    stack<int> st;
    for(int i = 1; i <= n; ++i) r[i] = n + 1;
    for(int i = 1; i <= n; ++i) {
        while(!st.empty() && arr[st.top()] < arr[i]) {
            r[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
}
 
void update_l() {
    stack<int> st;
    for(int i = 1; i <= n; ++i) l[i] = 0;
    for(int i = n; i >= 1; --i) {
        while(!st.empty() && arr[st.top()] < arr[i]) {
            l[st.top()] = i;
            st.pop();
        }
        st.push(i);
    }
}
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> n;
    for(int i = 1; i <= n; ++i) cin >> arr[i];
    for(int i = 1; i <= n; ++i) tmp[i] = {arr[i], i};
    sort(tmp + 1, tmp + n + 1, greater<pii>());
    for(int i = 1; i <= n; ++i) ord[i] = tmp[i].second;
    update_sum(); update_l(); update_r();
    
    cin >> q;
    while(q--) {
        int t, a, b; cin >> t >> a >> b;
        if(t == 1) {
            arr[a] = b;
            update_sum(); update_l(); update_r();
            update_sort(a);
        }
        else {
            int ans = 0, mx = 0;
            for(int i = 1; i <= n; ++i) chk[i] = 0;
            for(int i = 1; i <= n; ++i) graph[i].clear();
            for(int i = a; i <= b; ++i) mx = max(mx, arr[i]);
            for(int i = a; i <= b; ++i) {
                ll tmp = sum[min(r[i], b + 1) - 1] - sum[max(l[i], a - 1)];
                if(r[i] <= b && tmp >= (ll)arr[r[i]]) graph[r[i]].push_back(i);
                if(l[i] >= a && tmp >= (ll)arr[l[i]]) graph[l[i]].push_back(i);
            }
            
            queue<int> q;
            for(int i = a; i <= b; ++i) if(arr[i] == mx) q.push(i), chk[i] = 1;
            while(!q.empty()) {
                int cur = q.front(); q.pop();
                ++ans;
                for(auto v : graph[cur]) {
                    if(!chk[v]) chk[v] = 1, q.push(v);
                }
            }
            cout << ans << '\n';
        }
    }
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 6 ms 2684 KB Output is correct
6 Correct 3 ms 2732 KB Output is correct
7 Correct 4 ms 2644 KB Output is correct
8 Correct 3 ms 2644 KB Output is correct
9 Correct 3 ms 2644 KB Output is correct
10 Correct 4 ms 2684 KB Output is correct
11 Correct 3 ms 2644 KB Output is correct
12 Correct 4 ms 2644 KB Output is correct
13 Correct 3 ms 2644 KB Output is correct
14 Correct 4 ms 2644 KB Output is correct
15 Correct 4 ms 2680 KB Output is correct
16 Correct 3 ms 2644 KB Output is correct
17 Correct 5 ms 2644 KB Output is correct
18 Correct 3 ms 2644 KB Output is correct
19 Correct 4 ms 2644 KB Output is correct
20 Correct 4 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 19 ms 7036 KB Output is correct
3 Correct 17 ms 6640 KB Output is correct
4 Correct 19 ms 7112 KB Output is correct
5 Correct 17 ms 6740 KB Output is correct
6 Correct 25 ms 8544 KB Output is correct
7 Correct 25 ms 7508 KB Output is correct
8 Correct 26 ms 8524 KB Output is correct
9 Correct 24 ms 7428 KB Output is correct
10 Correct 20 ms 7404 KB Output is correct
11 Correct 16 ms 6484 KB Output is correct
12 Correct 24 ms 7772 KB Output is correct
13 Correct 24 ms 7712 KB Output is correct
14 Correct 21 ms 7380 KB Output is correct
15 Correct 23 ms 7388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 6 ms 2684 KB Output is correct
6 Correct 3 ms 2732 KB Output is correct
7 Correct 4 ms 2644 KB Output is correct
8 Correct 3 ms 2644 KB Output is correct
9 Correct 3 ms 2644 KB Output is correct
10 Correct 4 ms 2684 KB Output is correct
11 Correct 3 ms 2644 KB Output is correct
12 Correct 4 ms 2644 KB Output is correct
13 Correct 3 ms 2644 KB Output is correct
14 Correct 4 ms 2644 KB Output is correct
15 Correct 4 ms 2680 KB Output is correct
16 Correct 3 ms 2644 KB Output is correct
17 Correct 5 ms 2644 KB Output is correct
18 Correct 3 ms 2644 KB Output is correct
19 Correct 4 ms 2644 KB Output is correct
20 Correct 4 ms 2644 KB Output is correct
21 Correct 1 ms 2644 KB Output is correct
22 Correct 19 ms 7036 KB Output is correct
23 Correct 17 ms 6640 KB Output is correct
24 Correct 19 ms 7112 KB Output is correct
25 Correct 17 ms 6740 KB Output is correct
26 Correct 25 ms 8544 KB Output is correct
27 Correct 25 ms 7508 KB Output is correct
28 Correct 26 ms 8524 KB Output is correct
29 Correct 24 ms 7428 KB Output is correct
30 Correct 20 ms 7404 KB Output is correct
31 Correct 16 ms 6484 KB Output is correct
32 Correct 24 ms 7772 KB Output is correct
33 Correct 24 ms 7712 KB Output is correct
34 Correct 21 ms 7380 KB Output is correct
35 Correct 23 ms 7388 KB Output is correct
36 Correct 799 ms 6964 KB Output is correct
37 Correct 653 ms 6696 KB Output is correct
38 Correct 401 ms 7180 KB Output is correct
39 Correct 1042 ms 6980 KB Output is correct
40 Correct 452 ms 6868 KB Output is correct
41 Correct 1468 ms 8596 KB Output is correct
42 Correct 1127 ms 8600 KB Output is correct
43 Correct 1277 ms 7532 KB Output is correct
44 Correct 838 ms 7528 KB Output is correct
45 Correct 855 ms 6860 KB Output is correct
46 Correct 728 ms 7224 KB Output is correct
47 Correct 471 ms 7120 KB Output is correct
48 Correct 2101 ms 7844 KB Output is correct
49 Correct 824 ms 7776 KB Output is correct
50 Correct 1303 ms 7460 KB Output is correct
51 Correct 2011 ms 7452 KB Output is correct
52 Correct 1722 ms 7500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 19 ms 7036 KB Output is correct
3 Correct 17 ms 6640 KB Output is correct
4 Correct 19 ms 7112 KB Output is correct
5 Correct 17 ms 6740 KB Output is correct
6 Correct 25 ms 8544 KB Output is correct
7 Correct 25 ms 7508 KB Output is correct
8 Correct 26 ms 8524 KB Output is correct
9 Correct 24 ms 7428 KB Output is correct
10 Correct 20 ms 7404 KB Output is correct
11 Correct 16 ms 6484 KB Output is correct
12 Correct 24 ms 7772 KB Output is correct
13 Correct 24 ms 7712 KB Output is correct
14 Correct 21 ms 7380 KB Output is correct
15 Correct 23 ms 7388 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Execution timed out 4077 ms 7224 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 19 ms 7036 KB Output is correct
3 Correct 17 ms 6640 KB Output is correct
4 Correct 19 ms 7112 KB Output is correct
5 Correct 17 ms 6740 KB Output is correct
6 Correct 25 ms 8544 KB Output is correct
7 Correct 25 ms 7508 KB Output is correct
8 Correct 26 ms 8524 KB Output is correct
9 Correct 24 ms 7428 KB Output is correct
10 Correct 20 ms 7404 KB Output is correct
11 Correct 16 ms 6484 KB Output is correct
12 Correct 24 ms 7772 KB Output is correct
13 Correct 24 ms 7712 KB Output is correct
14 Correct 21 ms 7380 KB Output is correct
15 Correct 23 ms 7388 KB Output is correct
16 Correct 1 ms 2680 KB Output is correct
17 Execution timed out 4067 ms 7700 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 6 ms 2684 KB Output is correct
6 Correct 3 ms 2732 KB Output is correct
7 Correct 4 ms 2644 KB Output is correct
8 Correct 3 ms 2644 KB Output is correct
9 Correct 3 ms 2644 KB Output is correct
10 Correct 4 ms 2684 KB Output is correct
11 Correct 3 ms 2644 KB Output is correct
12 Correct 4 ms 2644 KB Output is correct
13 Correct 3 ms 2644 KB Output is correct
14 Correct 4 ms 2644 KB Output is correct
15 Correct 4 ms 2680 KB Output is correct
16 Correct 3 ms 2644 KB Output is correct
17 Correct 5 ms 2644 KB Output is correct
18 Correct 3 ms 2644 KB Output is correct
19 Correct 4 ms 2644 KB Output is correct
20 Correct 4 ms 2644 KB Output is correct
21 Correct 1 ms 2644 KB Output is correct
22 Correct 19 ms 7036 KB Output is correct
23 Correct 17 ms 6640 KB Output is correct
24 Correct 19 ms 7112 KB Output is correct
25 Correct 17 ms 6740 KB Output is correct
26 Correct 25 ms 8544 KB Output is correct
27 Correct 25 ms 7508 KB Output is correct
28 Correct 26 ms 8524 KB Output is correct
29 Correct 24 ms 7428 KB Output is correct
30 Correct 20 ms 7404 KB Output is correct
31 Correct 16 ms 6484 KB Output is correct
32 Correct 24 ms 7772 KB Output is correct
33 Correct 24 ms 7712 KB Output is correct
34 Correct 21 ms 7380 KB Output is correct
35 Correct 23 ms 7388 KB Output is correct
36 Correct 799 ms 6964 KB Output is correct
37 Correct 653 ms 6696 KB Output is correct
38 Correct 401 ms 7180 KB Output is correct
39 Correct 1042 ms 6980 KB Output is correct
40 Correct 452 ms 6868 KB Output is correct
41 Correct 1468 ms 8596 KB Output is correct
42 Correct 1127 ms 8600 KB Output is correct
43 Correct 1277 ms 7532 KB Output is correct
44 Correct 838 ms 7528 KB Output is correct
45 Correct 855 ms 6860 KB Output is correct
46 Correct 728 ms 7224 KB Output is correct
47 Correct 471 ms 7120 KB Output is correct
48 Correct 2101 ms 7844 KB Output is correct
49 Correct 824 ms 7776 KB Output is correct
50 Correct 1303 ms 7460 KB Output is correct
51 Correct 2011 ms 7452 KB Output is correct
52 Correct 1722 ms 7500 KB Output is correct
53 Correct 2 ms 2644 KB Output is correct
54 Execution timed out 4077 ms 7224 KB Time limit exceeded
55 Halted 0 ms 0 KB -