結果
問題 | No.1079 まお |
ユーザー | 👑 jupiro |
提出日時 | 2020-06-13 01:13:13 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 379 ms / 2,000 ms |
コード長 | 2,288 bytes |
コンパイル時間 | 1,440 ms |
コンパイル使用メモリ | 141,060 KB |
実行使用メモリ | 8,088 KB |
最終ジャッジ日時 | 2023-09-06 11:37:35 |
合計ジャッジ時間 | 7,806 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 1 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 1 ms
4,376 KB |
testcase_04 | AC | 2 ms
4,376 KB |
testcase_05 | AC | 2 ms
4,380 KB |
testcase_06 | AC | 2 ms
4,376 KB |
testcase_07 | AC | 3 ms
4,380 KB |
testcase_08 | AC | 3 ms
4,380 KB |
testcase_09 | AC | 4 ms
4,376 KB |
testcase_10 | AC | 3 ms
4,380 KB |
testcase_11 | AC | 3 ms
4,376 KB |
testcase_12 | AC | 160 ms
5,432 KB |
testcase_13 | AC | 157 ms
5,672 KB |
testcase_14 | AC | 236 ms
6,572 KB |
testcase_15 | AC | 249 ms
6,992 KB |
testcase_16 | AC | 259 ms
7,308 KB |
testcase_17 | AC | 329 ms
7,200 KB |
testcase_18 | AC | 259 ms
6,104 KB |
testcase_19 | AC | 350 ms
7,232 KB |
testcase_20 | AC | 341 ms
7,152 KB |
testcase_21 | AC | 322 ms
6,908 KB |
testcase_22 | AC | 339 ms
7,580 KB |
testcase_23 | AC | 331 ms
7,692 KB |
testcase_24 | AC | 350 ms
7,592 KB |
testcase_25 | AC | 357 ms
7,832 KB |
testcase_26 | AC | 379 ms
7,828 KB |
testcase_27 | AC | 36 ms
4,932 KB |
testcase_28 | AC | 152 ms
6,284 KB |
testcase_29 | AC | 172 ms
8,068 KB |
testcase_30 | AC | 174 ms
8,088 KB |
testcase_31 | AC | 42 ms
4,880 KB |
ソースコード
#include <cstdio> #include <iostream> #include <string> #include <sstream> #include <stack> #include <algorithm> #include <cmath> #include <queue> #include <map> #include <set> #include <cstdlib> #include <bitset> #include <tuple> #include <assert.h> #include <deque> #include <bitset> #include <iomanip> #include <limits> #include <chrono> #include <random> #include <array> #include <unordered_map> #include <functional> #include <complex> #include <numeric> template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } constexpr long long MAX = 5100000; constexpr long long INF = 1LL << 60; constexpr int inf = 1000000007; constexpr long long mod = 1000000007LL; //constexpr long long mod = 998244353LL; const long double PI = acos((long double)(-1)); using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; ll n, k; vector<ll> a; ll calc(vector<ll> &v1, vector<ll> &v2) { ll idx = 0; //v2のidx ll mn = INF; //最小値 ll mn_cnt = 0; //minの最小値(1以外はout) ll res = 0; map<ll, pair<ll, ll>> mp; //値、個数、総和 for (ll i = 0; i < v1.size(); i++) { if (chmin(mn, v1[i])) mn_cnt = 1; else if (mn == v1[i]) mn_cnt++; if (mn_cnt > 1) continue; while (idx < v2.size() and v2[idx] > mn) { mp[v2[idx]].first++; mp[v2[idx]].second += v1.size() + idx + 1; idx++; } if (mp.find(k - v1[i]) != mp.end()) res += mp[k - v1[i]].second - (v1.size() - i - 1) * mp[k - v1[i]].first; } return res; } ll f(int left, int right) { if (right - left <= 0) return 0; if (right - left == 1) return a[left] * 2 == k; ll mid = (left + right) >> 1; ll res = f(left, mid) + f(mid, right); vector<ll> v1, v2; for (int i = left; i < mid; i++) v1.emplace_back(a[i]); for (int i = mid; i < right; i++) v2.emplace_back(a[i]); reverse(v1.begin(), v1.end()); res += calc(v1, v2); //v1側に最小値がある場合 res += calc(v2, v1); //v2側に最小値がある場合 return res; } int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ scanf("%lld %lld", &n, &k); a.resize(n); for (int i = 0; i < n; i++) scanf("%lld", &a[i]); cout << f(0, n) << endl; return 0; }