Submission #75816888
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define MOD 1000000007
#define INF 987654321
#define PI 3.1415926535
int len;
int tree[300001];
int sum(int k)
{
int s = 0;
while (k >= 1)
{
s += tree[k];
k -= k & -k;
}
return s;
}
void add(int k, int x)
{
while (k <= len)
{
tree[k] += x;
k += k & -k;
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
int n, q;
cin >> n >> q;
string s;
cin >> s;
vector<int> v;
int cur = 1;
for (int i = 1; i < n; i++)
{
if (s[i] != 'X' && s[i] == s[i - 1])
{
cur++;
}
else
{
v.push_back(cur);
cur = 1;
}
}
v.push_back(cur);
len = v.size();
for (int i = 0; i < len; i++)
{
add(i + 1, v[i] / 2);
}
for (int i = 1; i < len; i++)
{
v[i] += v[i - 1];
}
while (q--)
{
int l, r;
cin >> l >> r;
int ans = 0;
int vl = lower_bound(v.begin(), v.end(), l) - v.begin();
int vr = lower_bound(v.begin(), v.end(), r) - v.begin();
if (vl == vr)
{
ans += (r - l + 1) / 2;
}
else
{
ans += (v[vl] - l + 1) / 2;
ans += (r - v[vr - 1]) / 2;
}
if (vl + 1 <= vr - 1)
{
ans += (sum(vr) - sum(vl + 1));
}
cout << ans << '\n';
}
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - Coloring |
| User | Nyso |
| Language | C++23 (GCC 15.2.0) |
| Score | 100 |
| Code Size | 1627 Byte |
| Status | AC |
| Exec Time | 99 ms |
| Memory | 6232 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 100 / 100 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00-sample-001.txt |
| All | 00-sample-001.txt, 01-001.txt, 01-002.txt, 01-003.txt, 01-004.txt, 01-005.txt, 01-006.txt, 01-007.txt, 01-008.txt, 01-009.txt, 01-010.txt, 01-011.txt, 01-012.txt, 01-013.txt, 01-014.txt, 01-015.txt, 01-016.txt, 01-017.txt, 01-018.txt, 01-019.txt, 01-020.txt, 01-021.txt, 01-022.txt, 01-023.txt, 01-024.txt, 01-025.txt, 01-026.txt, 01-027.txt, 01-028.txt, 01-029.txt, 01-030.txt, 01-031.txt, 01-032.txt, 01-033.txt, 01-034.txt, 01-035.txt, 01-036.txt, 01-037.txt, 01-038.txt, 01-039.txt, 01-040.txt, 01-041.txt, 01-042.txt, 01-043.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00-sample-001.txt | AC | 13 ms | 3392 KiB |
| 01-001.txt | AC | 96 ms | 5636 KiB |
| 01-002.txt | AC | 97 ms | 5592 KiB |
| 01-003.txt | AC | 97 ms | 5624 KiB |
| 01-004.txt | AC | 97 ms | 5752 KiB |
| 01-005.txt | AC | 97 ms | 5584 KiB |
| 01-006.txt | AC | 98 ms | 5640 KiB |
| 01-007.txt | AC | 97 ms | 5596 KiB |
| 01-008.txt | AC | 97 ms | 5608 KiB |
| 01-009.txt | AC | 97 ms | 5720 KiB |
| 01-010.txt | AC | 97 ms | 5584 KiB |
| 01-011.txt | AC | 97 ms | 5864 KiB |
| 01-012.txt | AC | 96 ms | 5748 KiB |
| 01-013.txt | AC | 97 ms | 5804 KiB |
| 01-014.txt | AC | 97 ms | 5668 KiB |
| 01-015.txt | AC | 96 ms | 5692 KiB |
| 01-016.txt | AC | 29 ms | 3924 KiB |
| 01-017.txt | AC | 29 ms | 3908 KiB |
| 01-018.txt | AC | 29 ms | 3928 KiB |
| 01-019.txt | AC | 99 ms | 6148 KiB |
| 01-020.txt | AC | 78 ms | 6104 KiB |
| 01-021.txt | AC | 78 ms | 6108 KiB |
| 01-022.txt | AC | 78 ms | 6232 KiB |
| 01-023.txt | AC | 80 ms | 5308 KiB |
| 01-024.txt | AC | 80 ms | 5112 KiB |
| 01-025.txt | AC | 66 ms | 4576 KiB |
| 01-026.txt | AC | 66 ms | 4344 KiB |
| 01-027.txt | AC | 69 ms | 4300 KiB |
| 01-028.txt | AC | 54 ms | 3800 KiB |
| 01-029.txt | AC | 97 ms | 6160 KiB |
| 01-030.txt | AC | 73 ms | 4536 KiB |
| 01-031.txt | AC | 75 ms | 4324 KiB |
| 01-032.txt | AC | 65 ms | 4464 KiB |
| 01-033.txt | AC | 42 ms | 3816 KiB |
| 01-034.txt | AC | 65 ms | 5112 KiB |
| 01-035.txt | AC | 65 ms | 5080 KiB |
| 01-036.txt | AC | 65 ms | 5108 KiB |
| 01-037.txt | AC | 74 ms | 4592 KiB |
| 01-038.txt | AC | 1 ms | 3352 KiB |
| 01-039.txt | AC | 1 ms | 3372 KiB |
| 01-040.txt | AC | 1 ms | 3436 KiB |
| 01-041.txt | AC | 1 ms | 3428 KiB |
| 01-042.txt | AC | 1 ms | 3516 KiB |
| 01-043.txt | AC | 1 ms | 3528 KiB |