結果
| 問題 | No.3328 岩井ツリーグラフ |
| コンテスト | |
| ユーザー |
Taiki0715
|
| 提出日時 | 2026-09-04 13:31:11 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 56 ms / 2,000 ms |
| + 384µs | |
| コード長 | 14,209 bytes |
| 記録 | |
| コンパイル時間 | 2,060 ms |
| コンパイル使用メモリ | 338,512 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2026-09-04 13:37:57 |
| 合計ジャッジ時間 | 4,977 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2>istream &operator>>(istream&,pair<T1,T2>&);
template<typename...Args>istream &operator>>(istream&,tuple<Args...>&a);
template<typename T>istream &operator>>(istream&is,vector<T>&a);
template<typename T,size_t N>istream &operator>>(istream&is,array<T,N>&a);
template<typename T1,typename T2>
istream &operator>>(istream&is,pair<T1,T2>&a){
is>>a.first>>a.second;
return is;
}
template<size_t pos,typename...Args>
void read_tuple(istream&is,tuple<Args...>&a){
if constexpr(pos<tuple_size<tuple<Args...>>::value){
is>>get<pos>(a);
read_tuple<pos+1>(is,a);
}
}
template<typename...Args>
istream &operator>>(istream&is,tuple<Args...>&a){
read_tuple<0>(is,a);
return is;
}
template<typename T>
istream &operator>>(istream&is,vector<T>&a){
for(T&x:a)is>>x;
return is;
}
template<typename T,size_t N>
istream &operator>>(istream&is,array<T,N>&a){
for(T&x:a)is>>x;
return is;
}
template<typename T1,typename T2>ostream &operator<<(ostream&os,const pair<T1,T2>&);
template<typename...Args>ostream &operator<<(ostream&os,const tuple<Args...>&);
template<typename T>ostream &operator<<(ostream&os,const vector<T>&);
template<typename T,typename Seq,typename Comp>ostream &operator<<(ostream&os,priority_queue<T,Seq,Comp>);
template<typename T>ostream &operator<<(ostream&os,queue<T>);
template<typename T>ostream &operator<<(ostream&os,deque<T>);
template<typename T>ostream &operator<<(ostream&os,stack<T>);
template<typename T,size_t N>ostream &operator<<(ostream&os,const array<T,N>&);
template<typename Key,typename Val,typename Comp>ostream &operator<<(ostream&os,const map<Key,Val,Comp>&);
template<typename Key,typename Val,typename Hash>ostream &operator<<(ostream&os,const unordered_map<Key,Val,Hash>&);
template<typename T,typename Comp>ostream &operator<<(ostream&os,const set<T,Comp>&);
template<typename T,typename Comp>ostream &operator<<(ostream&os,const multiset<T,Comp>&);
template<typename T,typename Hash>ostream &operator<<(ostream&os,const unordered_set<T,Hash>&);
template<typename T1,typename T2>
ostream &operator<<(ostream&os,const pair<T1,T2>&a){
os<<a.first<<' '<<a.second;
return os;
}
template<size_t pos,typename...Args>
void write_tuple(ostream&os,const tuple<Args...>&a){
if constexpr(pos<tuple_size<tuple<Args...>>::value){
if constexpr(pos>0)os<<' ';
os<<get<pos>(a);
write_tuple<pos+1>(os,a);
}
}
template<typename...Args>
ostream &operator<<(ostream&os,const tuple<Args...>&a){
write_tuple<0>(os,a);
return os;
}
template<typename T>
ostream &operator<<(ostream&os,const vector<T>&a){
os<<'{';
for(int i=0;i<(int)a.size();i++){
os<<a[i];
if(i+1!=a.size())os<<',';
}
os<<'}';
return os;
}
template<typename T,typename Seq,typename Comp>
ostream &operator<<(ostream&os,priority_queue<T,Seq,Comp>a){
os<<'{';
if(!a.empty()){
os<<a.top();a.pop();
while(!a.empty()){
os<<',';
os<<a.top();
a.pop();
}
}
os<<'}';
return os;
}
template<typename T>
ostream &operator<<(ostream&os,queue<T>a){
os<<'{';
if(!a.empty()){
os<<a.front();a.pop();
while(!a.empty()){
os<<',';
os<<a.front();
a.pop();
}
}
os<<'}';
return os;
}
template<typename T>
ostream &operator<<(ostream&os,deque<T>a){
os<<'{';
if(!a.empty()){
os<<a.front();a.pop_front();
while(!a.empty()){
os<<',';
os<<a.front();
a.pop_front();
}
}
os<<'}';
return os;
}
template<typename T>
ostream &operator<<(ostream&os,stack<T>a){
os<<'{';
if(!a.empty()){
os<<a.top();a.pop();
while(!a.empty()){
os<<',';
os<<a.top();
a.pop();
}
}
os<<'}';
return os;
}
template<typename T,size_t N>
ostream &operator<<(ostream&os,const array<T,N>&a){
os<<'{';
for(int i=0;i<(int)a.size();i++){
os<<a[i];
if(i+1!=a.size())os<<',';
}
os<<'}';
return os;
}
template<typename Key,typename Val,typename Comp>
ostream &operator<<(ostream&os,const map<Key,Val,Comp>&a){
if(a.empty()){
os<<"{}";
return os;
}
auto itr=a.begin();
os<<"{["<<itr->first<<","<<itr->second<<']';
while(++itr!=a.end())os<<",["<<itr->first<<','<<itr->second<<']';
os<<'}';
return os;
}
template<typename Key,typename Val,typename Hash>
ostream &operator<<(ostream&os,const unordered_map<Key,Val,Hash>&a){
if(a.empty()){
os<<"{}";
return os;
}
auto itr=a.begin();
os<<"{["<<itr->first<<","<<itr->second<<']';
while(++itr!=a.end())os<<",["<<itr->first<<','<<itr->second<<']';
os<<'}';
return os;
}
template<typename T,typename Comp>
ostream &operator<<(ostream&os,const set<T,Comp>&a){
if(a.empty()){
os<<"{}";
return os;
}
auto itr=a.begin();
os<<'{'<<*itr;
while(++itr!=a.end())os<<','<<*itr;
os<<'}';
return os;
}
template<typename T,typename Comp>
ostream &operator<<(ostream&os,const multiset<T,Comp>&a){
if(a.empty()){
os<<"{}";
return os;
}
auto itr=a.begin();
os<<'{'<<*itr;
while(++itr!=a.end())os<<','<<*itr;
os<<'}';
return os;
}
template<typename T,typename Hash>
ostream &operator<<(ostream&os,const unordered_set<T,Hash>&a){
if(a.empty()){
os<<"{}";
return os;
}
auto itr=a.begin();
os<<'{'<<*itr;
while(++itr!=a.end())os<<','<<*itr;
os<<'}';
return os;
}
using namespace std;
using ll=long long;
using ull=unsigned long long;
using P=pair<ll,ll>;
template<typename T>using minque=priority_queue<T,vector<T>,greater<T>>;
template<typename T>bool chmax(T &a,const T &b){return (a<b?(a=b,true):false);}
template<typename T>bool chmin(T &a,const T &b){return (a>b?(a=b,true):false);}
template<typename T1,typename T2>void operator++(pair<T1,T2>&a,int){a.first++,a.second++;}
template<typename T1,typename T2>void operator--(pair<T1,T2>&a,int){a.first--,a.second--;}
template<typename T>void operator++(vector<T>&a,int){for(auto &i:a)i++;}
template<typename T>void operator--(vector<T>&a,int){for(auto &i:a)i--;}
#define overload3(_1,_2,_3,name,...) name
#define rep1(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define rep(...) overload3(__VA_ARGS__,rep2,rep1)(__VA_ARGS__)
#define reps(i,l,r) rep2(i,l,r)
#define all(x) x.begin(),x.end()
#define pcnt(x) __builtin_popcountll(x)
#define fin(x) return cout<<(x)<<'\n',static_cast<void>(0)
#define yn(x) cout<<((x)?"Yes\n":"No\n")
#define uniq(x) sort(all(x)),x.erase(unique(all(x)),x.end())
template<typename T>
inline int fkey(vector<T>&z,T key){return lower_bound(z.begin(),z.end(),key)-z.begin();}
ll myceil(ll a,ll b){return (a+b-1)/b;}
template<typename T,size_t n,size_t id=0>
auto vec(const int (&d)[n],const T &init=T()){
if constexpr (id<n)return vector(d[id],vec<T,n,id+1>(d,init));
else return init;
}
#ifdef LOCAL
#include<debug.h>
#define SWITCH(a,b) (a)
#else
#define debug(...) static_cast<void>(0)
#define debugg(...) static_cast<void>(0)
#define SWITCH(a,b) (b)
#endif
struct Timer{
clock_t start;
Timer(){
start=clock();
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout<<fixed<<setprecision(16);
}
inline double now(){return (double)(clock()-start)/1000;}
#ifdef LOCAL
~Timer(){
cerr<<"time:";
cerr<<now();
cerr<<"ms\n";
}
#endif
}timer;
void SOLVE();
int main(){
int testcase=1;
//cin>>testcase;
for(int i=0;i<testcase;i++){
SOLVE();
}
}
#include<type_traits>
#include<optional>
#include<initializer_list>
constexpr bool isprime_constexpr(unsigned long long n){
if(n==998244353)return true;
if(n==1000000007)return true;
if(n<64)return 2891462833508853932ll>>n&1;
if(n%2==0)return false;
unsigned long long d=n-1;
int s=0;
while(!(d&1))d>>=1,s++;
int q=63;
while(!(d>>q))q--;
unsigned long long r=n;
for(int i=0;i<5;i++)r*=2-r*n;
auto redc=[&r,&n](__uint128_t x)->unsigned long long {
x=(x+__uint128_t((unsigned long long)x*-r)*n)>>64;
return x>=n?x-n:x;
};
__uint128_t r2=-__uint128_t(n)%n;
unsigned long long one=redc(r2);
for(unsigned long long base:{2,325,9375,28178,450775,9780504,1795265022}){
if(base%n==0)continue;
unsigned long long a=base=redc((base%n)*r2);
for(int i=q-1;i>=0;i--){
a=redc(__uint128_t(a)*a);
if(d>>i&1)a=redc(__uint128_t(a)*base);
}
if(a==one)continue;
for(int i=1;a!=n-one;i++){
if(i>=s)return false;
a=redc(__uint128_t(a)*a);
}
}
return true;
}
constexpr std::pair<long long,long long>ext_gcd(long long a,long long b){
if(b==0)return std::make_pair(1,0);
auto [x,y]=ext_gcd(b,a%b);
std::swap(x,y);
return std::make_pair(x,y-a/b*x);
}
template<std::signed_integral T>
constexpr std::pair<T,T> inv_mod(T a,T b){
a%=b;
if(a<0)a+=b;
if(a==0)return std::make_pair(b,0);
T s=b,t=a;
T m0=0,m1=1;
while(t){
T u=s/t;
s-=t*u;
m0-=m1*u;
std::swap(s,t);
std::swap(m0,m1);
}
if(m0<0)m0+=b/s;
return std::make_pair(s,m0);
}
template<auto m>
struct modint{
static_assert(1<=m&&m<(1ull<<63));
using value_type=std::conditional_t<((m>>31)==0),uint32_t,uint64_t>;
using mul_type=std::conditional_t<((m>>31)==0),uint64_t,__uint128_t>;
private:
value_type v;
static constexpr value_type umod=m;
constexpr modint sqrt_impl()const{
if(this->val()<=1)return *this;
if(umod%8==1){
modint b=2;
while(b.pow((umod-1)/2).val()==1)b++;
value_type m2=umod-1;
int e=0;
while(m2%2==0)m2>>=1,e++;
modint x=this->pow((m2-1)/2);
modint y=(*this)*x*x;
x*=*this;
modint z=b.pow(m2);
while(y.val()!=1){
int j=0;
modint t=y;
while(t.val()!=1)t*=t,j++;
z=z.pow((value_type(1))<<(e-j-1));
x*=z;
z*=z;
y*=z;
e=j;
}
return x;
}
else if(umod%8==5){
modint res=this->pow((umod+3)/8);
if((res*res).val()==this->val())return res;
else return res*modint(2).pow((umod-1)/4);
}
else return this->pow((umod+1)/4);
}
template<typename U,std::enable_if_t<std::unsigned_integral<U>||std::is_same_v<U,__uint128_t>,std::nullptr_t> =nullptr>
static constexpr value_type take_mod(U x){
if constexpr(std::numeric_limits<U>::max()<umod)return x;
if constexpr(umod==(1ull<<61)-1){
value_type res=(x>>61)+(x&umod);
if(res>=umod)res-=umod;
return res;
}
if constexpr(umod==(1ull<<61)-(1ull<<24)+1){
static constexpr value_type mask=(1ull<<61)-1;
value_type high=x>>61,low=x&mask;
mul_type t=low+(mul_type(high)<<24)-high;
high=t>>61,low=t&mask;
low=low+(mul_type(high)<<24)-high;
if(low>=umod)low-=umod;
return low;
}
return x%umod;
}
public:
constexpr modint():v(0){}
template<typename U,std::enable_if_t<std::signed_integral<U>||std::is_same_v<U,__int128_t>,std::nullptr_t> =nullptr>
constexpr modint(U x){
x%=std::make_signed_t<value_type>(umod);
v=x>=0?x:x+umod;
}
template<typename U,std::enable_if_t<std::unsigned_integral<U>||std::is_same_v<U,__uint128_t>,std::nullptr_t> =nullptr>
constexpr modint(U x):v(take_mod<U>(x)){}
static constexpr value_type mod(){return umod;}
template<typename U>
static constexpr modint raw(U x){
modint res;
res.v=x;
return res;
}
constexpr std::make_signed_t<value_type> val()const{return v;}
constexpr modint &operator+=(const modint&b){
this->v+=b.v;
if(this->v>=umod)this->v-=umod;
return *this;
}
constexpr modint &operator-=(const modint&b){
this->v-=b.v;
if(this->v>=umod)this->v+=umod;
return *this;
}
constexpr modint &operator*=(const modint&b){
this->v=take_mod(mul_type(this->v)*mul_type(b.v));
return *this;
}
constexpr modint &operator/=(const modint&b){return *this*=b.inv();}
constexpr modint operator+()const{return *this;}
constexpr modint operator-()const{return modint()-*this;}
friend constexpr modint operator+(const modint&a,const modint&b){return modint(a)+=b;}
friend constexpr modint operator-(const modint&a,const modint&b){return modint(a)-=b;}
friend constexpr modint operator*(const modint&a,const modint&b){return modint(a)*=b;}
friend constexpr modint operator/(const modint&a,const modint&b){return modint(a)/=b;}
constexpr auto operator<=>(const modint&)const=default;
constexpr modint operator++(int){
modint res=*this;
this->v++;
if(this->v==umod)this->v=0;
return res;
}
constexpr modint operator--(int){
modint res=*this;
if(this->v==0)this->v=umod;
this->v--;
return res;
}
template<std::integral U>
constexpr modint pow(U k)const{
if constexpr(std::is_signed_v<U>){
assert(0<=k);
}
modint res=1,a(*this);
while(k){
if(k&1)res*=a;
a*=a;
k>>=1;
}
return res;
}
constexpr modint inv()const{
if constexpr(isprime_constexpr(umod)){
if(std::is_constant_evaluated()){
if(v==0){
throw "no inverse";
}
}
else assert(v!=0);
return pow(umod-2);
}
else{
modint res;
auto [g,x]=inv_mod<std::make_signed_t<value_type>>(this->v,umod);
if(std::is_constant_evaluated()){
if(g!=1){
throw "no inverse";
}
}
else assert(g==1);
res.v=x;
return res;
}
}
std::optional<modint>sqrt()const{
if(this->val()<=1||this->pow((umod-1)/2)==1)return std::make_optional(this->sqrt_impl());
else return std::nullopt;
}
friend std::istream &operator>>(std::istream&is,modint&b){
long long a;
is>>a;
b=modint(a);
return is;
}
friend std::ostream &operator<<(std::ostream&os,const modint&b){
os<<b.val();
return os;
}
};
template<auto m>
struct std::hash<modint<m>>{
std::size_t operator()(modint<m>x)const{
return std::hash<typename modint<m>::value_type>(x.val());
}
};
using mint998=modint<998244353>;
using mint107=modint<1000000007>;
using mint61=modint<2305843009213693951>;
using mint6124=modint<2305843009196916737>;
using mint=mint998;
void SOLVE(){
int n;
cin>>n;
vector<mint>a(n);
cin>>a;
mint s=reduce(all(a))+1;
mint ans=0;
rep(i,n){
mint c=a[i];
ans+=s*c*(c+1)/2;
ans-=c*(c+1)*(c*2+1)/6;
}
cout<<ans<<endl;
}
Taiki0715