M

Untitled

public
marinapottahmalfol2785 Dec 02, 2023 Never 78
Clone
C++ paste1.cpp 62 lines (50 loc) | 1.55 KB
1
#include <iostream>
2
3
int main()
4
{
5
/// Cho mot tro choi, bao gom [nChamp] con tuong
6
int nChamp;
7
std::cin >> nChamp;
8
9
/// va trong ban do co [nLaneCount] duong di
10
int nLaneCount;
11
std::cin >> nLaneCount;
12
13
/// minh can dem so tuong co toc la [sTarget]
14
std::string sTarget;
15
std::cin >> sTarget;
16
17
/// minh se tao mang de dem cac tuong o cung mot duong di
18
int nTargetCount[nLaneCount + 1];
19
for (int nLane = 0; nLane <= nLaneCount; ++nLane)
20
{
21
nTargetCount[nLane] = 0;
22
}
23
24
/// Nhan thong tin cua n tuong, ve toc [sHero] va duong di [nLane]
25
for (int i = 1; i <= nChamp; ++i)
26
{
27
std::string sHero;
28
std::cin >> sHero;
29
30
int nLane;
31
std::cin >> nLane;
32
33
if (sHero == "Demacia")
34
{
35
nTargetCount[nLane]++;
36
}
37
}
38
39
int nPrefixSum[nLaneCount + 1];
40
nPrefixSum[0] = 0;
41
for (int nLane = 1; nLane <= nLaneCount; ++nLane)
42
{
43
nPrefixSum[nLane] = nPrefixSum[nLane - 1] + nTargetCount[nLane];
44
std::cout << "nPrefixSum[" << nLane << "] = " << nPrefixSum[nLane] << std::endl;
45
}
46
47
/// Xu li q truy van
48
int q;
49
std::cin >> q;
50
51
/// Moi truy van se hoi xem tu lan [Left] toi lan [Right]
52
/// dem xem co bao nhieu tuong cung toc voi [sTarget]
53
for (int i = 1; i <= q; ++i)
54
{
55
int nLeft, nRight;
56
std::cin >> nLeft >> nRight;
57
58
std::cout << nPrefixSum[nRight] - nPrefixSum[nLeft - 1] << std::endl;
59
}
60
61
return 0;
62
}