結果

問題 No.2359 A in S ?
ユーザー pointNpointN
提出日時 2023-06-23 22:41:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,199 bytes
コンパイル時間 2,101 ms
コンパイル使用メモリ 142,780 KB
実行使用メモリ 21,216 KB
最終ジャッジ日時 2023-09-13 17:45:54
合計ジャッジ時間 15,589 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
14,644 KB
testcase_01 AC 27 ms
14,640 KB
testcase_02 RE -
testcase_03 AC 28 ms
14,580 KB
testcase_04 AC 991 ms
20,788 KB
testcase_05 RE -
testcase_06 AC 990 ms
21,112 KB
testcase_07 WA -
testcase_08 RE -
testcase_09 AC 747 ms
21,044 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 1,004 ms
20,948 KB
testcase_13 AC 999 ms
21,216 KB
testcase_14 AC 984 ms
21,064 KB
testcase_15 AC 748 ms
21,044 KB
testcase_16 AC 993 ms
20,844 KB
testcase_17 AC 983 ms
21,132 KB
testcase_18 AC 994 ms
21,048 KB
testcase_19 AC 1,007 ms
21,020 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(y>=B){
      for(ll a=x;a<mx;a+=y){
        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(y<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