Submission #37029460
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
int f[100010];
signed main() {
int n,q;
string s;
cin>>n>>q>>s;
for(int i=0;i<s.size();i++)
if(i>0) f[i]=f[i-1]+(s[i]!=s[i-1]);
while(q--) {
int l,r;
cin>>l>>r;
l--,r--;
if(s[l]==s[r]) cout<<(f[r]-f[l]+1)/2<<endl;
else cout<<(f[r]-f[l])/2+1<<endl;
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | A - My Last ABC Problem |
| User | cxm1024 |
| Language | C++ (GCC 9.2.1) |
| Score | 500 |
| Code Size | 342 Byte |
| Status | AC |
| Exec Time | 197 ms |
| Memory | 4104 KiB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:8:15: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
8 | for(int i=0;i<s.size();i++)
| ~^~~~~~~~~
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 500 / 500 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 01.txt |
| All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 01.txt | AC | 11 ms | 3548 KiB |
| 02.txt | AC | 180 ms | 3480 KiB |
| 03.txt | AC | 180 ms | 3480 KiB |
| 04.txt | AC | 184 ms | 3592 KiB |
| 05.txt | AC | 197 ms | 3944 KiB |
| 06.txt | AC | 196 ms | 3944 KiB |
| 07.txt | AC | 197 ms | 4104 KiB |
| 08.txt | AC | 197 ms | 4008 KiB |
| 09.txt | AC | 197 ms | 4104 KiB |