結果

問題 No.2359 A in S ?
ユーザー pointNpointN
提出日時 2023-06-23 22:44:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,015 ms / 2,000 ms
コード長 2,199 bytes
コンパイル時間 1,589 ms
コンパイル使用メモリ 143,848 KB
実行使用メモリ 21,124 KB
最終ジャッジ日時 2023-09-13 17:49:55
合計ジャッジ時間 17,618 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
14,584 KB
testcase_01 AC 28 ms
14,640 KB
testcase_02 AC 36 ms
14,648 KB
testcase_03 AC 28 ms
14,592 KB
testcase_04 AC 977 ms
20,920 KB
testcase_05 AC 998 ms
20,184 KB
testcase_06 AC 990 ms
21,104 KB
testcase_07 AC 555 ms
20,248 KB
testcase_08 AC 690 ms
20,248 KB
testcase_09 AC 768 ms
21,012 KB
testcase_10 AC 739 ms
20,188 KB
testcase_11 AC 735 ms
20,068 KB
testcase_12 AC 1,004 ms
20,900 KB
testcase_13 AC 979 ms
21,036 KB
testcase_14 AC 984 ms
20,932 KB
testcase_15 AC 755 ms
21,008 KB
testcase_16 AC 1,015 ms
21,124 KB
testcase_17 AC 1,014 ms
20,920 KB
testcase_18 AC 989 ms
21,008 KB
testcase_19 AC 999 ms
21,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
//#include <atcoder/all>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,M; cin >> N >> M;
  int mx = 100010;
  vector<int> A(mx,0);
  vector<vector<int>> Q(N);
  int B = 320;
  vector<vector<vector<int>>> qv(B,vector<vector<int>>(B));
  vector<vector<vector<int>>> qa(B,vector<vector<int>>(B));
  rep(i,B){
    rep(j,B){
      qv[i][j].pb(0);
      qv[i][j].pb(1<<30);
    }
  }
  rep(i,N){
    int l,r,x,y; cin >> l >> r >> x >> y;
    Q[i] = {l,r,x,y};
    if(x>=B){
      for(ll a=y;a<mx;a+=x){
        if(l<=a&&a<=r) A[a]++;
      }
    }
    else{
      qv[x][y].pb(l);
      qv[x][y].pb(r+1);
    }
  }
  rep(i,B){
    rep(j,B){
      sort(all(qv[i][j]));
      qv[i][j].erase(unique(qv[i][j].begin(),qv[i][j].end()),qv[i][j].end());
      qa[i][j].assign(sz(qv[i][j]),0);
    }
  }
  rep(i,N){
    int l=Q[i][0], r=Q[i][1], x=Q[i][2], y=Q[i][3];
    if(x<B){
      int i1 = lower_bound(all(qv[x][y]),l)-qv[x][y].begin();
      int i2 = lower_bound(all(qv[x][y]),r+1)-qv[x][y].begin();
      qa[x][y][i1]++;
      qa[x][y][i2]--;
    }
  }
  rep(i,B){
    rep(j,B){
      rep(k,sz(qa[i][j])-1) qa[i][j][k+1] += qa[i][j][k];
    }
  }
  while(M--){
    int a; cin >> a;
    int ans = A[a];
    for(int x=1;x<B;x++){
      int y = a % x;
      int idx = prev(upper_bound(all(qv[x][y]),a))-qv[x][y].begin();
      ans += qa[x][y][idx];
    }
    cout << ans << '\n';
  }

  return 0;
};
0