結果
問題 | No.1036 Make One With GCD 2 |
ユーザー | mugen_1337 |
提出日時 | 2020-04-25 20:17:37 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 280 ms / 2,000 ms |
コード長 | 2,105 bytes |
コンパイル時間 | 2,028 ms |
コンパイル使用メモリ | 207,196 KB |
実行使用メモリ | 15,584 KB |
最終ジャッジ日時 | 2023-10-14 20:01:23 |
合計ジャッジ時間 | 10,294 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 150 ms
7,580 KB |
testcase_01 | AC | 114 ms
6,964 KB |
testcase_02 | AC | 118 ms
15,584 KB |
testcase_03 | AC | 15 ms
4,648 KB |
testcase_04 | AC | 24 ms
5,660 KB |
testcase_05 | AC | 1 ms
4,352 KB |
testcase_06 | AC | 2 ms
4,348 KB |
testcase_07 | AC | 38 ms
4,848 KB |
testcase_08 | AC | 31 ms
4,352 KB |
testcase_09 | AC | 168 ms
6,908 KB |
testcase_10 | AC | 157 ms
6,844 KB |
testcase_11 | AC | 170 ms
6,908 KB |
testcase_12 | AC | 162 ms
6,720 KB |
testcase_13 | AC | 280 ms
6,640 KB |
testcase_14 | AC | 280 ms
6,892 KB |
testcase_15 | AC | 248 ms
6,648 KB |
testcase_16 | AC | 266 ms
6,436 KB |
testcase_17 | AC | 265 ms
6,664 KB |
testcase_18 | AC | 2 ms
4,352 KB |
testcase_19 | AC | 2 ms
4,352 KB |
testcase_20 | AC | 2 ms
4,348 KB |
testcase_21 | AC | 2 ms
4,352 KB |
testcase_22 | AC | 250 ms
6,536 KB |
testcase_23 | AC | 191 ms
5,736 KB |
testcase_24 | AC | 262 ms
6,748 KB |
testcase_25 | AC | 241 ms
6,404 KB |
testcase_26 | AC | 250 ms
6,476 KB |
testcase_27 | AC | 1 ms
4,348 KB |
testcase_28 | AC | 1 ms
4,348 KB |
testcase_29 | AC | 2 ms
4,348 KB |
testcase_30 | AC | 2 ms
4,348 KB |
testcase_31 | AC | 2 ms
4,352 KB |
testcase_32 | AC | 2 ms
4,348 KB |
testcase_33 | AC | 2 ms
4,348 KB |
testcase_34 | AC | 2 ms
4,348 KB |
testcase_35 | AC | 2 ms
4,348 KB |
testcase_36 | AC | 2 ms
4,348 KB |
testcase_37 | AC | 1 ms
4,348 KB |
testcase_38 | AC | 116 ms
15,572 KB |
testcase_39 | AC | 154 ms
6,992 KB |
testcase_40 | AC | 198 ms
5,704 KB |
testcase_41 | AC | 177 ms
6,892 KB |
testcase_42 | AC | 189 ms
7,016 KB |
testcase_43 | AC | 180 ms
9,112 KB |
testcase_44 | AC | 179 ms
8,152 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; #define ALL(x) x.begin(),x.end() #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; #define INF 1000000000 #define mod 1000000007 using ll=long long; const ll LINF=1001002003004005006ll; int dx[]={1,0,-1,0}; int dy[]={0,1,0,-1}; // ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;} template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;} // Monoid Sliding-Window-AGregation template<typename Monoid> struct SWAG{ using F=function<Monoid(Monoid,Monoid)>; const F f; const Monoid gen; stack<pair<Monoid,Monoid>> fr,ba; SWAG(const F f,const Monoid &gen):f(f),gen(gen){} Monoid get(){ ll a=fr.empty()?gen:fr.top().second; ll b=ba.empty()?gen:ba.top().second; return f(a,b); } void push(Monoid x){ if(ba.empty()) ba.push(make_pair(x,x)); else ba.push(make_pair(x,f(ba.top().second,x))); } void pop(){ if(empty()) return ; if(!fr.empty()) fr.pop(); else{ while(!ba.empty()){ pair<Monoid,Monoid> p=ba.top();ba.pop(); if(fr.empty()) fr.push(make_pair(p.first,p.first)); else fr.push(make_pair(p.first,f(p.first,fr.top().second))); } fr.pop(); } } size_t size(){ return fr.size()+ba.size(); } bool empty(){ return size()==0; } }; signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n;cin>>n; vector<ll> a(n); rep(i,n){ cin>>a[i]; } function<ll(ll,ll)> g=[](ll a,ll b){return gcd(a,b);}; SWAG<ll> que(g,0); ll r=0,res=0; for(ll l=0;l<n;l++){ while(r<n and g(que.get(),a[r])!=1){ que.push(a[r]); r++; } res+=(ll)que.size(); if(r==l){ r++; }else{ que.pop(); } } cout<<(ll)n*(n+1)/2-res<<endl; return 0; }