Submission #657196

# Submission time Handle Problem Language Result Execution time Memory
657196 2022-11-09T05:46:21 Z dilaylay_dilaylaylay Money (IZhO17_money) C++17
0 / 100
1 ms 340 KB
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")

using namespace std;

#define int long long
#define ll long long
#define vi vector<long long>
#define pb push_back
#define sz(s) (int)s.size()
#define all(v) v.begin(), v.end()
#define show(a) cerr << #a <<" -> "<< a <<"\n"
#define pp pair<int,int>
#define FF first
#define SS second
#define endl "\n"

const int N = 1e6 + 2, N3 = 1e3 + 6, inf = 1e9 + 7, LOG = 20;
map<char, int> md{{'N', 0}, {'E', 1}, {'S', 2}, {'W', 3}};
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
string stepDir = "RDLU";

int n, a[N], t[N * 4];

void upd(int pos, int new_val, int v = 1, int tl = 1, int tr = N) {
	if (tl == tr) {
		t[v] = new_val;
	}
	else {
		int tm = (tl + tr) / 2;
		if (pos <= tm) {
			upd(pos, new_val, v * 2, tl, tm);
		}
		else {
			upd(pos, new_val, v * 2 + 1, tm + 1, tr);
		}
		t[v] = t[v * 2] + t[v * 2 + 1];
	}
}

int get_sum(int l, int r, int v = 1, int tl = 1, int tr = N) {
	if (l <= tl && tr <= r) {
        return t[v];
    }
    if (tr < l || r < tl) {
        return 0;
    }
    int tm = (tl + tr) / 2;
    return get_sum(l, r, v * 2, tl, tm) + get_sum(l, r, v * 2 + 1, tm + 1, tr);
}


main () {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);

	cin >> n;
	int ans = n;
	for (int i = 1; i <= n; i++) {
        cin >> a[i];
        if (a[i - 1] + 1 == a[i]) {
            ans--;
            upd(a[i - 1], 1);
            upd(a[i], 1);
        }
	}

	for (int i = 1; i <= n; i++) {
        if (a[i] != a[i + 1] && a[i] < a[i + 1] - 1) {
            if (get_sum(a[i] + 1, a[i + 1] - 1) == a[i + 1] - a[i] - 1) ans--;
        }
	}

	cout << ans;

	return 0;
}

Compilation message

money.cpp:13: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
   13 | #pragma comment(linker, "/stack:200000000")
      | 
money.cpp:67:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   67 | main () {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -