結果

問題 No.2956 Substitute with Average
ユーザー nana
提出日時 2025-01-04 19:26:13
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 105 ms / 3,000 ms
コード長 3,698 bytes
コンパイル時間 11,488 ms
コンパイル使用メモリ 641,676 KB
実行使用メモリ 51,320 KB
最終ジャッジ日時 2025-01-04 19:26:28
合計ジャッジ時間 14,450 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include "atcoder/all"
#include <bits/stdc++.h>
#include <climits>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
#include <boost/functional/hash.hpp>
//
using Bint = boost::multiprecision::cpp_int;
// 101024(TLE)
using BReal =
boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1024>>;
using Rat = boost::rational<Bint>;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
//
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace atcoder;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T &a, T b) { return ((a>b) ? (a = b, true) : (false));}
#define rep(i,s,n) for(int i=s;i<(int)(n);i++)
//decrease rep(s, n)
#define drep(i,s,n) for(int i=n-1;i>=s;i--)
const long long inf = 1LL<<60;
typedef long long ll;
typedef long double ld;
typedef __int128_t l3;
//pairsecondsort(p.begin(),p.end(),cmp)
#define cmp [](pair<ll,ll> a, pair<ll,ll> b){return a.second<b.second;}
//cmpArg := , atan2l(y, x); atan2l(y, x) = [-pi, pi]
#define cmpArg [](const auto &p1, const auto &p2) { return atan2l(p1.second, p1.first) < atan2l(p2.second, p2.first); }
typedef pair<int,int> pi;
typedef pair<long long, long long> P;
typedef pair<ll, pair<ll,ll> > PP;
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define vint vector<int>
#define vvint vector<vector<int>>
#define vmint vector<mint>
#define vvmint vector<vector<mint>>
#define vvch vector<vector<char>>
#define vch vector<char>
#define vvpi vector<vector<pi>>
#define vpi vector<pi>
#define pb push_back
#define eb emplace_back
#define YES cout<<"Yes"<<endl;
#define NO cout<<"No"<<endl;
#define YN { cout << "Yes" << endl; } else { cout << "No" << endl; }
#define all(x) x.begin(), x.end()
#define fi first
#define se second
template<class T>istream& operator>>(istream& i, vector<T> &v) { rep(j___, 0, size(v))i >> v[j___]; return i; }
#define UNIQUE(x) sort(all(x)), x.erase(unique(all(x)), x.end())
int pc(ll x) { return __builtin_popcount(x); } //1 pop count
void cincout(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); cout<< fixed << setprecision(15); }
bool out_grid(ll i, ll j, ll h, ll w) { return (!(0<=i && i<h && 0<=j && j<w)); }
#define vc_cout(v){ ll n=v.size(); rep(i___,0,n) cout << v[i___] << " "; cout << endl; }
#define vv_cout(v){ ll n=v.size(); rep(i___,0,n) { rep(j___,0,v[i___].size()){ cout << v[i___][j___] << " ";} cout << endl; }}
using mint = modint998244353;
int main()
{
int n; cin >> n;
vint a(n); cin >> a;
const int m = 30;
const int R = n*m;
vint zero(2*R+1), non_zero(2*R+1);
ll ans = ll(n)*(n+1)/2;
for(int x=1;x<=m;x++) {
vint b(n); rep(i,0,n) b[i] = a[i] - x;
vint s(n+1); rep(i,1,n+1) s[i] = s[i-1] + b[i-1];
rep(i,0,n) {
if(b[i] == 0) {
zero[s[i]+R]++;
ans -= zero[R+s[i+1]] + non_zero[R+s[i+1]];
} else {
non_zero[s[i]+R]++;
ans -= zero[R+s[i+1]];
}
}
rep(i,0,n) {
if(b[i] == 0) zero[s[i]+R] = 0;
else non_zero[R+s[i]] = 0;
}
}
ans++;
cout << ans << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0