Submission #2403983


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}


int gcd(int a, int b) {
  return b == 0 ? a : gcd(b, a % b);
}

const int MAX_N = 112345;
int a[MAX_N];

map<int, ll> ans_map;
map<int, ll> add_map;

void add(int at, ll by) {
  // cout << "add(" << at << "," << by << ")" << endl;
  ans_map[at] += by;
  add_map[at] += by;
}

int main2() {
  ans_map.clear();
  add_map.clear();
  int N = nextInt();
  int Q = nextInt();
  REP(i, N) a[i] = nextInt();
 
  REP(i, N) {
    auto last_add = add_map;
    add_map.clear();
    add(a[i], 1);
    for (auto it = last_add.begin(); it != last_add.end(); ++it) {
      const int x = it->first;
      const int num = it->second;
      add(gcd(x, a[i]), num);
    }
    // pv(ALL(ans_map));
    // cout << "add:"; pv(ALL(add_map));
  }
  REP(q, Q) {
    int x = nextInt();
    ll ans = 0;
    ans = ans_map[x];
    printf("%lld\n", ans);
  }
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}

Submission Info

Submission Time
Task D - GCD区間
User hs484
Language C++14 (GCC 5.4.1)
Score 100
Code Size 1550 Byte
Status AC
Exec Time 184 ms
Memory 7040 KB

Compile Error

./Main.cpp: In function ‘int nextInt()’:
./Main.cpp:14:39: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
 int nextInt() { int x; scanf("%d", &x); return x;}
                                       ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 3
AC × 30
Set Name Test Cases
Sample subtask0_sample_01.txt, subtask0_sample_02.txt, subtask0_sample_03.txt
All subtask0_sample_01.txt, subtask0_sample_02.txt, subtask0_sample_03.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_20.txt, subtask1_21.txt, subtask1_22.txt, subtask1_23.txt, subtask1_24.txt, subtask1_25.txt, subtask1_26.txt, subtask1_27.txt
Case Name Status Exec Time Memory
subtask0_sample_01.txt AC 1 ms 256 KB
subtask0_sample_02.txt AC 1 ms 256 KB
subtask0_sample_03.txt AC 1 ms 256 KB
subtask1_01.txt AC 2 ms 256 KB
subtask1_02.txt AC 2 ms 256 KB
subtask1_03.txt AC 2 ms 256 KB
subtask1_04.txt AC 137 ms 7040 KB
subtask1_05.txt AC 139 ms 7040 KB
subtask1_06.txt AC 21 ms 640 KB
subtask1_07.txt AC 19 ms 640 KB
subtask1_08.txt AC 19 ms 640 KB
subtask1_09.txt AC 59 ms 768 KB
subtask1_10.txt AC 59 ms 768 KB
subtask1_11.txt AC 184 ms 7040 KB
subtask1_12.txt AC 27 ms 640 KB
subtask1_13.txt AC 62 ms 640 KB
subtask1_14.txt AC 30 ms 640 KB
subtask1_15.txt AC 50 ms 640 KB
subtask1_16.txt AC 59 ms 640 KB
subtask1_17.txt AC 66 ms 640 KB
subtask1_18.txt AC 31 ms 640 KB
subtask1_19.txt AC 32 ms 640 KB
subtask1_20.txt AC 29 ms 640 KB
subtask1_21.txt AC 21 ms 640 KB
subtask1_22.txt AC 28 ms 640 KB
subtask1_23.txt AC 38 ms 640 KB
subtask1_24.txt AC 25 ms 640 KB
subtask1_25.txt AC 27 ms 640 KB
subtask1_26.txt AC 44 ms 6656 KB
subtask1_27.txt AC 71 ms 7040 KB