Submission #401492

#TimeUsernameProblemLanguageResultExecution timeMemory
401492tranxuanbachBrperm (RMI20_brperm)C++17
100 / 100
205 ms15724 KiB
#include "brperm.h" #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #pragma GCC optimize("O3,unroll-loops,no-stack-protector") #pragma GCC target("mmx,sse,sse2,sse3,ssse3,sse4,avx,avx2,fma") #define endl '\n' #define fi first #define se second #define For(i, l, r) for (int i = l; i < r; i++) #define ForE(i, l, r) for (int i = l; i <= r; i++) #define FordE(i, l, r) for (int i = l; i >= r; i--) #define Fora(v, a) for (auto v: a) #define bend(a) a.begin(), a.end() #define isz(a) ((signed)a.size()) typedef long long ll; typedef long double ld; typedef pair <int, int> pii; typedef vector <int> vi; typedef vector <pii> vpii; typedef vector <vi> vvi; const int N = 5e5 + 5; const int BIT = 18; namespace Namespace{ bool sub3 = 1; int n; char s[N]; int cnta[N], cntb[N]; vi posa, posb; int rev[BIT + 1][1 << BIT]; mt19937 rando(chrono::steady_clock::now().time_since_epoch().count()); } using namespace Namespace; void init(int cacn, const char cacs[]){ n = cacn; For(i, 0, n){ s[i] = cacs[i]; cnta[i] = (i == 0 ? 0 : cnta[i - 1]); cntb[i] = (i == 0 ? 0 : cntb[i - 1]); if (s[i] == 'a'){ cnta[i]++; posa.emplace_back(i); } if (s[i] == 'b'){ cntb[i]++; posb.emplace_back(i); } if (s[i] != 'a' and s[i] != 'b'){ sub3 = 0; } } rev[0][0] = 0; ForE(l, 1, BIT){ For(i, 0, (1 << l)){ rev[l][i] = 0; For(j, 0, l){ rev[l][i] = rev[l][i] * 2 + ((i & (1 << j)) ? 1 : 0); } } } return; } int query(int i, int k){ if (i + (1 << k) - 1 >= n){ return 0; } if (k <= 0){ For(j, 0, (1 << k)){ if (s[i + j] != s[i + rev[k][j]]){ return 0; } } return 1; } if (sub3){ if (cnta[i + (1 << k) - 1] - (i == 0 ? 0 : cnta[i - 1]) <= (1 << 10)){ int idx = lower_bound(bend(posa), i) - posa.begin(); while (idx < isz(posa) and posa[idx] <= i + (1 << k) - 1){ if (s[posa[idx]] != s[i + rev[k][posa[idx] - i]]){ return 0; } idx++; } return 1; } else if (cntb[i + (1 << k) - 1] - (i == 0 ? 0 : cntb[i - 1]) <= (1 << 10)){ int idx = lower_bound(bend(posb), i) - posb.begin(); while (idx < isz(posb) and posb[idx] <= i + (1 << k) - 1){ if (s[posb[idx]] != s[i + rev[k][posb[idx] - i]]){ return 0; } idx++; } return 1; } else{ return 0; } } For(j, 0, (1 << k)){ if (s[i + j] != s[i + rev[k][j]]){ return 0; } } return 1; } /* ==================================================+ INPUT: | --------------------------------------------------| --------------------------------------------------| ==================================================+ OUTPUT: | --------------------------------------------------| --------------------------------------------------| ==================================================+ */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...