답안 #341273

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
341273 2020-12-29T10:37:00 Z Dilshod_Imomov Simple game (IZhO17_game) C++17
49 / 100
1000 ms 13792 KB
# include <bits/stdc++.h>
# define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
# define int long long
# define fi first
# define se second
 
using namespace std;
 
const int N = 1e6 + 7;
const int mod = 1e9 + 7;

int a[N], dp[N];

int32_t main() {
    speed; 
    int n, m;
    cin >> n >> m;
    for ( int i = 1; i <= n; i++ ) {
        cin >> a[i];
    }
    for ( int i = 2; i <= n; i++ ) {
        int l = a[i - 1], r = a[i];
        if ( l > r ) {
            swap( l, r );
        }
        dp[l]++;
        dp[r + 1]--;
    }
    for ( int i = 1; i < N; i++ ) {
        dp[i] += dp[i - 1];
    }
    vector < pair < int, pair < int, int > > > vc;
    int s2 = 1;
    for ( int i = 1; i <= m; i++ ) {
        int t;
        cin >> t;
        if ( t == 2 ) {
            int h, cnt = 0;
            cin >> h;
            vc.push_back( { 2, { h, 0 } } );
        }
        else {
            int pos, val;
            cin >> pos >> val;
            vc.push_back( { 1, { pos, val } } );
            s2 = 0;
        }
    }
    if ( s2 ) {
        for ( int i = 0; i < m; i++ ) {
            int h = vc[i].second.first;
            cout << dp[h] << '\n';
        }
        return 0;
    }
    for ( int i = 0; i < m; i++ ) {
        int t = vc[i].first;
        if ( t == 2 ) {
            int h = vc[i].second.first, cnt = 0;
            for ( int i = 2; i <= n; i++ ) {
                if ( (a[i - 1] < h && a[i] > h) || (a[i - 1] > h && a[i] < h) ) {
                    cnt++;
                }
            }
            cout << cnt << '\n';
        }
        else {
            int pos = vc[i].se.fi, val = vc[i].se.se;
            a[pos] = val;
        }
    }
}

Compilation message

game.cpp: In function 'int32_t main()':
game.cpp:38:20: warning: unused variable 'cnt' [-Wunused-variable]
   38 |             int h, cnt = 0;
      |                    ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 8172 KB Output is correct
2 Correct 9 ms 8300 KB Output is correct
3 Correct 9 ms 8300 KB Output is correct
4 Correct 9 ms 8300 KB Output is correct
5 Correct 9 ms 8300 KB Output is correct
6 Correct 9 ms 8428 KB Output is correct
7 Correct 7 ms 8300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 8172 KB Output is correct
2 Correct 9 ms 8300 KB Output is correct
3 Correct 9 ms 8300 KB Output is correct
4 Correct 9 ms 8300 KB Output is correct
5 Correct 9 ms 8300 KB Output is correct
6 Correct 9 ms 8428 KB Output is correct
7 Correct 7 ms 8300 KB Output is correct
8 Correct 41 ms 12896 KB Output is correct
9 Correct 56 ms 13664 KB Output is correct
10 Correct 61 ms 13664 KB Output is correct
11 Correct 39 ms 12896 KB Output is correct
12 Correct 47 ms 13408 KB Output is correct
13 Correct 56 ms 13532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 8172 KB Output is correct
2 Correct 9 ms 8300 KB Output is correct
3 Correct 9 ms 8300 KB Output is correct
4 Correct 9 ms 8300 KB Output is correct
5 Correct 9 ms 8300 KB Output is correct
6 Correct 9 ms 8428 KB Output is correct
7 Correct 7 ms 8300 KB Output is correct
8 Correct 41 ms 12896 KB Output is correct
9 Correct 56 ms 13664 KB Output is correct
10 Correct 61 ms 13664 KB Output is correct
11 Correct 39 ms 12896 KB Output is correct
12 Correct 47 ms 13408 KB Output is correct
13 Correct 56 ms 13532 KB Output is correct
14 Execution timed out 1031 ms 13792 KB Time limit exceeded
15 Halted 0 ms 0 KB -