# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
118329 | popovicirobert | Lollipop (POI11_liz) | C++14 | 719 ms | 36488 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44
using namespace std;
const int MAXN = (int) 1e6;
int where[2 * MAXN + 1], sp[MAXN + 1];
char str[MAXN + 1];
int n;
inline int find(int val) {
int res = 0;
for(int step = 1 << 19; step; step >>= 1) {
if(res + step <= n && sp[res + step] <= val) {
res += step;
}
}
if(sp[res] != val) res = -1;
return res;
}
int main() {
//ifstream cin("B.in");
//ofstream cout("B.out");
int i, m;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m >> str + 1;
int pos = -1;
for(i = 1; i <= n; i++) {
sp[i] = sp[i - 1];
if(str[i] == 'W') {
if(pos == -1) {
pos = i;
}
sp[i]++;
}
else {
sp[i] += 2;
}
where[sp[i]] = i;
}
vector <int> sums[2], ind[2];
if(pos != -1) {
for(i = pos; i <= n; i++) {
int cur = sp[i] - sp[pos - 1];
sums[cur & 1].push_back(cur);
ind[cur & 1].push_back(i);
}
}
while(m--) {
int x;
cin >> x;
if(sp[n] < x) {
cout << "NIE\n";
continue;
}
if(where[x] > 0) {
cout << 1 << " " << where[x] << "\n";
continue;
}
if(pos != -1) {
int r = find(sp[pos] + x);
if(r != -1) {
cout << pos + 1 << " " << r << "\n";
continue;
}
r = find(sp[pos - 1] + x);
if(r != -1) {
cout << pos << " " << r << "\n";
continue;
}
r = upper_bound(sums[x & 1].begin(), sums[x & 1].end(), x) - sums[x & 1].begin();
if(sums[x & 1].size() && r > 0 && sums[x & 1][r - 1] + 2 * (pos - 1) >= x) {
cout << pos - (x - sums[x & 1][r - 1]) / 2 << " " << ind[x & 1][r - 1] << "\n";
continue;
}
}
cout << "NIE\n";
}
//cin.close();
//cout.close();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |