結果
問題 | No.1079 まお |
ユーザー | IKyopro |
提出日時 | 2020-06-12 22:29:57 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,296 bytes |
コンパイル時間 | 3,031 ms |
コンパイル使用メモリ | 216,652 KB |
実行使用メモリ | 16,916 KB |
最終ジャッジ日時 | 2023-09-06 10:45:25 |
合計ジャッジ時間 | 6,948 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,380 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 73 ms
9,892 KB |
testcase_13 | AC | 78 ms
11,252 KB |
testcase_14 | AC | 105 ms
12,236 KB |
testcase_15 | AC | 123 ms
13,752 KB |
testcase_16 | AC | 144 ms
15,164 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 171 ms
16,720 KB |
testcase_23 | AC | 180 ms
16,688 KB |
testcase_24 | AC | 192 ms
16,916 KB |
testcase_25 | AC | 191 ms
16,728 KB |
testcase_26 | AC | 186 ms
16,732 KB |
testcase_27 | AC | 11 ms
4,380 KB |
testcase_28 | AC | 40 ms
10,696 KB |
testcase_29 | AC | 72 ms
16,688 KB |
testcase_30 | AC | 75 ms
16,788 KB |
testcase_31 | AC | 12 ms
4,380 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class T, class U> using Pa = pair<T, U>; template <class T> using vec = vector<T>; template <class T> using vvec = vector<vec<T>>; template<class T> class SWAG{ private: struct node{ T val,sum; node(const T& val, const T& sum):val(val),sum(sum){} }; using F = function<T(T,T)>; stack<node> front_stack,back_stack; F op; public: SWAG(const F op):op(op),front_stack(),back_stack(){}; void push(const T& x){ if(back_stack.empty()) back_stack.emplace(x,x); else{ T s{op(back_stack.top().sum,x)}; back_stack.emplace(x,s); } } void pop(){ if(front_stack.empty()){ front_stack.emplace(back_stack.top().val,back_stack.top().val); back_stack.pop(); while(!back_stack.empty()){ T s{op(back_stack.top().val,front_stack.top().sum)}; front_stack.emplace(back_stack.top().val,s); back_stack.pop(); } } front_stack.pop(); } T result(){ if(front_stack.empty()) return back_stack.top().sum; else if(back_stack.empty()) return front_stack.top().sum; else return op(front_stack.top().sum,back_stack.top().sum); } bool empty(){ return front_stack.empty() && back_stack.empty(); } }; using P = pair<int,int>; int main(){ cin.tie(0); ios::sync_with_stdio(false); int N,K; cin >> N >> K; vec<int> A(N); for(auto& x:A) cin >> x; auto op = [](int a,int b){return min(a,b);}; SWAG<int> swag(op); map<int,ll> lsum,cnt; ll ans = 0; int r = 0; int l = 0; while(l<N){ while(r<N){ if(swag.empty() || swag.result()!=A[r]){ swag.push(A[r]); lsum[A[r]] += r-1; cnt[A[r]]++; if(cnt.count(K-A[r])) ans += cnt[K-A[r]]*r-lsum[K-A[r]]; r++; }else break; } while(!swag.empty()){ bool remove = A[l]==swag.result(); swag.pop(); lsum[A[l]] -= l-1; cnt[A[l]]--; l++; if(remove) break; } } cout << ans << "\n"; }