Qiita Teams that are logged in
You are not logged in to any team

Community
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What are the problem?

More than 1 year has passed since last update.

posted at

updated at

# 問題概要

\$A\$, \$C\$, \$G\$, \$T\$ からなる長さ \$N\$ の文字列 \$S\$ が与えられます。

# 制約条件

• \$2 \leqq N \leqq 10^5\$
• \$1 \leqq Q \leqq 10^5\$
• \$S\$は長さ\$N\$の文字列である。
• \$S\$の各文字は \$A\$, \$C\$, \$G\$, \$T\$ のいずれかである。
• \$1 \leqq l_i < r_i \leqq N\$

# 考えたこと

なので\$O(N)\$に収めないといけない。

あとは\$t[r]-t[l]\$が答えとなる。

# 解答

c.cs
``````using System;
using System.Linq;

class Program
{
static void Main(string[] args) {
int n = a[0];
int q = a[1];
for (int i = 0; i < n-1; i ++) {
if (s[i]=='A' && s[i+1]=='C') s[i] = 'a';
}
int[] t = new int[n];
t[0] = 0;
for (int i = 0; i < n-1; i ++) {
if (s[i]=='a') t[i+1] = t[i]+1;
else t[i+1] = t[i];
}
for(int i = 0; i < q; i ++) {
int l = b[0]-1;
int r = b[1]-1;
Console.WriteLine(t[r]-t[l]);
}
}
}
``````
Why not register and get more from Qiita?
1. We will deliver articles that match you
By following users and tags, you can catch up information on technical fields that you are interested in as a whole
2. you can read useful information later efficiently
By "stocking" the articles you like, you can search right away
0
Help us understand the problem. What are the problem?