Submission #957075

#TimeUsernameProblemLanguageResultExecution timeMemory
957075Mher777Sequence (APIO23_sequence)C++17
0 / 100
2060 ms15488 KiB
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <iomanip> #include <array> #include <string> #include <algorithm> #include <cmath> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <vector> #include <stack> #include <queue> #include <deque> #include <bitset> #include <list> #include <iterator> #include <numeric> #include <complex> #include <utility> #include <random> #include <cassert> #include <fstream> #include "sequence.h" using namespace std; mt19937 rnd(7069); typedef int itn; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef float fl; typedef long double ld; using vi = vector<int>; using vll = vector<ll>; using mii = map<int, int>; using mll = map<ll, ll>; using pii = pair<int, int>; using pll = pair<ll, ll>; #define ff first #define ss second #define pub push_back #define pob pop_back #define puf push_front #define pof pop_front #define mpr make_pair #define yes cout<<"Yes\n" #define no cout<<"No\n" #define all(x) (x).begin(), (x).end() const int MAX = int(2e9 + 5); const ll MAXL = ll(1e18) + 5ll; const int N = 500005; int a[N], t[N]; pii id[N]; int n, m, ans = 1; void add(int ind, int val) { while (ind <= n) { t[ind] += val; ind += (ind & -ind); } } int sum(int ind) { int ret = 0; while (ind) { ret += t[ind]; ind -= (ind & -ind); } return ret; } int qry(int l, int r) { return abs(sum(r) - sum(l - 1)); } int sequence(int N, std::vector<int> A) { n = N; for (int i = 1; i <= n; ++i) { a[i] = A[i - 1]; if (!id[a[i]].ff) id[a[i]].ff = i; id[a[i]].ss = i; if (a[i] > 1) add(i, 1); } for (int i = 1; i <= n; ++i) { int num = 0; if (!id[i].ff || id[i].ff == id[i].ss) continue; for (int j = id[i].ff + 1; j < id[i].ss; ++j) { if (a[j] > i) ++num; else --num; } if (abs(num) <= 2) return 2; } return 1; } /* 14 2 6 2 5 3 4 2 1 4 3 5 6 3 2 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...