Notice
Recent Posts
Recent Comments
Link
«   2026/06   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
Archives
Today
Total
관리 메뉴

dh-winternagi 님의 블로그

(16139) 인간-컴퓨터 상호작용 본문

백준 (C++)/Solve

(16139) 인간-컴퓨터 상호작용

dh-winternagi 2026. 4. 18. 08:04

https://www.acmicpc.net/problem/16139

단계별로 풀어보기

22단계(누적 합) 3번째

 

 

 

a~z 알파벳 26개에 대해 각각 등장한 횟수의 누적합 배열을 만들면 된다.

 

 

 

#include <iostream>
#include <vector>
using namespace std;

int main() 
{
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  
  string s;
  int q;
  
  cin >> s >> q;
  
  vector acc(s.length()+1, vector<int> (26));
  
  for(int i=0;i<s.length();i++){
    for(int j=0;j<26;j++)  acc[i+1][j]= acc[i][j];
    acc[i+1][s[i]-'a']++;
  }
  
  while(q--){
    char a;
    int l, r;
    
    cin >> a >> l >> r;
    
    cout << acc[r+1][a-'a']-acc[l][a-'a'] << "\n";
  }
  
  return 0;
}

'백준 (C++) > Solve' 카테고리의 다른 글

(11660) 구간 합 구하기 5  (0) 2026.04.18
(10986) 나머지 합  (0) 2026.04.18
(2559) 수열  (0) 2026.04.18
(11659) 구간 합 구하기 4  (0) 2026.04.17
(12865) 평범한 배낭  (0) 2026.04.17