Submission #45039440


Source Code Expand

#include <iostream>
#include <vector>

using namespace std;

int main(void)
{
  int n = 0, q = 0;
  cin >> n;

  vector<int> s1(n + 1);
  vector<int> s2(n + 1);

  for (int i = 0; i < n; i++)
  {
    int c = 0, p = 0;
    cin >> c >> p;

    /*
      edit 1: 1組の情報でなかった場合でも、区間和は、「前の要素と同じにする」という形で更新する
      元々 if で書いていたが、三項演算子のほうが綺麗
    */
    s1[i + 1] = s1[i] + (c == 1 ? p : 0);
    s2[i + 1] = s2[i] + (c == 2 ? p : 0);
  }
  cin >> q;

  for (int i = 0; i < q; i++)
  {
    int l = 0, r = 0;
    cin >> l >> r;
    l--;
    r--;

    /*
      両端を含む和を取りたい。
      a[r - 1]までの和になってしまうから、r + 1が必要
    */
    cout << s1[r + 1] - s1[l] << " " << s2[r + 1] - s2[l] << endl;
  }

  return 0;
}

Submission Info

Submission Time
Task 010 - Score Sum Queries(★2)
User coolwind0202
Language C++ (GCC 9.2.1)
Score 2
Code Size 912 Byte
Status AC
Exec Time 232 ms
Memory 3956 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 2 / 2
Status
AC × 4
AC × 18
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
All hand01.txt, hand02.txt, hand03.txt, hand04.txt, hand05.txt, hand06.txt, random01.txt, random02.txt, random03.txt, random04.txt, random05.txt, random06.txt, random07.txt, random08.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
Case Name Status Exec Time Memory
hand01.txt AC 8 ms 3552 KiB
hand02.txt AC 2 ms 3484 KiB
hand03.txt AC 228 ms 3800 KiB
hand04.txt AC 226 ms 3956 KiB
hand05.txt AC 213 ms 3800 KiB
hand06.txt AC 232 ms 3904 KiB
random01.txt AC 170 ms 3408 KiB
random02.txt AC 204 ms 3768 KiB
random03.txt AC 158 ms 3604 KiB
random04.txt AC 98 ms 3660 KiB
random05.txt AC 116 ms 3584 KiB
random06.txt AC 77 ms 3500 KiB
random07.txt AC 109 ms 3524 KiB
random08.txt AC 21 ms 3564 KiB
sample_01.txt AC 2 ms 3480 KiB
sample_02.txt AC 2 ms 3424 KiB
sample_03.txt AC 2 ms 3480 KiB
sample_04.txt AC 4 ms 3532 KiB