結果

問題 No.2359 A in S ?
ユーザー SSRSSSRS
提出日時 2023-06-23 21:32:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 400 ms / 2,000 ms
コード長 973 bytes
コンパイル時間 1,486 ms
コンパイル使用メモリ 170,132 KB
実行使用メモリ 136,972 KB
最終ジャッジ日時 2023-09-13 16:32:42
合計ジャッジ時間 10,153 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
136,696 KB
testcase_01 AC 134 ms
136,848 KB
testcase_02 AC 135 ms
136,820 KB
testcase_03 AC 135 ms
136,692 KB
testcase_04 AC 365 ms
136,968 KB
testcase_05 AC 399 ms
136,648 KB
testcase_06 AC 363 ms
136,696 KB
testcase_07 AC 400 ms
136,748 KB
testcase_08 AC 384 ms
136,820 KB
testcase_09 AC 365 ms
136,816 KB
testcase_10 AC 374 ms
136,964 KB
testcase_11 AC 387 ms
136,608 KB
testcase_12 AC 365 ms
136,820 KB
testcase_13 AC 362 ms
136,708 KB
testcase_14 AC 365 ms
136,672 KB
testcase_15 AC 366 ms
136,972 KB
testcase_16 AC 368 ms
136,816 KB
testcase_17 AC 369 ms
136,820 KB
testcase_18 AC 369 ms
136,624 KB
testcase_19 AC 369 ms
136,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int SQRT = 340;
const int MAX = 100000;
int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<int>> imos(SQRT, vector<int>(MAX + 2, 0));
  vector<int> cnt(MAX + 1, 0);
  for (int i = 0; i < N; i++){
    int L, R, X, Y;
    cin >> L >> R >> X >> Y;
    if (L % X <= Y){
      L += Y - L % X;
    } else {
      L += Y - L % X + X;
    }
    if (R % X >= Y){
      R -= R % X - Y;
    } else {
      R -= R % X - Y + X;
    }
    if (L <= R){
      if (X < SQRT){
        imos[X][L]++;
        if (R + X < MAX + 2){
          imos[X][R + X]--;
        }
      } else {
        for (int j = L; j <= R; j += X){
          cnt[j]++;
        }
      }
    }
  }
  for (int i = 1; i < SQRT; i++){
    for (int j = 0; j <= MAX; j++){
      if (j >= i){
        imos[i][j] += imos[i][j - i];
      }
      cnt[j] += imos[i][j];
    }
  }
  for (int i = 0; i < M; i++){
    int A;
    cin >> A;
    cout << cnt[A] << endl;
  }
}
0