# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
746459 |
2023-05-22T13:15:14 Z |
doowey |
Brperm (RMI20_brperm) |
C++14 |
|
359 ms |
9616 KB |
#include <bits/stdc++.h>
#include "brperm.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
const int MOD = (int)1e9 + 9;
const int N = (int)5e5 + 10;
vector<char> S;
vector<int> A[2];
void init(int n, const char s[]) {
for(int i = 0 ; i < n; i ++ ){
S.push_back(s[i]);
A[S[i] - 'a'].push_back(i);
}
}
int get_cnt(int id, int r){
int x = lower_bound(A[id].begin(), A[id].end(), r + 1) - A[id].begin();
return x;
}
int get(int id, int l, int r){
return get_cnt(id, r) - get_cnt(id, l - 1);
}
int query(int i, int k) {
if(i + (1 << k) - 1 >= S.size()) return 0;
int li = i;
int ri = i + (1 << k) - 1;
int ai = get(0, li, ri);
int bi = get(1, li, ri);
if(min(ai, bi) >= 40){
return 0;
}
int O = 0;
if(ai <= bi){
O = 0;
}
else{
O = 1;
}
int id = lower_bound(A[O].begin(), A[O].end(), li) - A[O].begin();
int cur;
int nw;
while(id < A[O].size() && A[O][id] <= ri){
cur = A[O][id] - li;
nw = 0;
for(int b = 0; b < k; b ++ ){
if((cur & (1 << b))){
nw |= (1 << (k - b - 1));
}
}
//cout << cur << " - " << nw << " |\n";
if(S[li + cur] != S[li + nw]) return 0;
id ++ ;
}
return 1;
}
Compilation message
brperm.cpp: In function 'int query(int, int)':
brperm.cpp:38:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | if(i + (1 << k) - 1 >= S.size()) return 0;
| ~~~~~~~~~~~~~~~~~^~~~~~~~~~~
brperm.cpp:56:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | while(id < A[O].size() && A[O][id] <= ri){
| ~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
301 ms |
7180 KB |
Output is correct |
2 |
Correct |
359 ms |
9616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |