QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#701962 | #9539. Disrupting Communications | ucup-team112# | AC ✓ | 333ms | 41212kb | C++20 | 22.1kb | 2024-11-02 15:00:47 | 2024-11-02 15:00:48 |
Judging History
answer
//#define _GLIBCXX_DEBUG
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debug_print.hpp>
#define OUT(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#define OUT(...) (static_cast<void>(0))
#endif
#define endl '\n'
#define lfs cout<<fixed<<setprecision(15)
#define ALL(a) (a).begin(),(a).end()
#define ALLR(a) (a).rbegin(),(a).rend()
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end())
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
namespace template_tute{
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 4.1e18;
using P = pair<ll, ll>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using QP = priority_queue<T,vector<T>,greater<T>>;
template<typename T1, typename T2>bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max<ll>({a,b,c})-min<ll>({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}
template<typename T1,typename T2,typename T3>void anss(T1 x,T2 y,T3 z){ans(x!=y,x,z);};
template<typename T>void debug(const T &v,ll h,ll w,string sv=" "){for(ll i=0;i<h;i++){cout<<v[i][0];for(ll j=1;j<w;j++)cout<<sv<<v[i][j];cout<<endl;}};
template<typename T>void debug(const T &v,ll n,string sv=" "){if(n!=0)cout<<v[0];for(ll i=1;i<n;i++)cout<<sv<<v[i];cout<<endl;};
template<typename T>void debug(const vector<T>&v){debug(v,v.size());}
template<typename T>void debug(const vector<vector<T>>&v){for(auto &vv:v)debug(vv,vv.size());}
template<typename T>void debug(stack<T> st){while(!st.empty()){cout<<st.top()<<" ";st.pop();}cout<<endl;}
template<typename T>void debug(queue<T> st){while(!st.empty()){cout<<st.front()<<" ";st.pop();}cout<<endl;}
template<typename T>void debug(deque<T> st){while(!st.empty()){cout<<st.front()<<" ";st.pop_front();}cout<<endl;}
template<typename T>void debug(PQ<T> st){while(!st.empty()){cout<<st.top()<<" ";st.pop();}cout<<endl;}
template<typename T>void debug(QP<T> st){while(!st.empty()){cout<<st.top()<<" ";st.pop();}cout<<endl;}
template<typename T>void debug(const set<T>&v){for(auto z:v)cout<<z<<" ";cout<<endl;}
template<typename T>void debug(const multiset<T>&v){for(auto z:v)cout<<z<<" ";cout<<endl;}
template<typename T,size_t size>void debug(const array<T, size> &a){for(auto z:a)cout<<z<<" ";cout<<endl;}
template<typename T,typename V>void debug(const map<T,V>&v){for(auto z:v)cout<<"["<<z.first<<"]="<<z.second<<",";cout<<endl;}
template<typename T>vector<vector<T>>vec(ll x, ll y, T w){vector<vector<T>>v(x,vector<T>(y,w));return v;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<typename T1, typename T2>ostream &operator<<(ostream &os, const pair<T1, T2>&p){return os << "(" << p.first << "," << p.second << ")";}
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v){os<<"[";for(auto &z:v)os << z << ",";os<<"]"; return os;}
template<typename T>void rearrange(vector<int>&ord, vector<T>&v){
auto tmp = v;
for(int i=0;i<tmp.size();i++)v[i] = tmp[ord[i]];
}
template<typename Head, typename... Tail>void rearrange(vector<int>&ord,Head&& head, Tail&&... tail){
rearrange(ord, head);
rearrange(ord, tail...);
}
template<typename T> vector<int> ascend(const vector<T>&v){
vector<int>ord(v.size());iota(ord.begin(),ord.end(),0);
sort(ord.begin(),ord.end(),[&](int i,int j){return make_pair(v[i],i)<make_pair(v[j],j);});
return ord;
}
template<typename T> vector<int> descend(const vector<T>&v){
vector<int>ord(v.size());iota(ord.begin(),ord.end(),0);
sort(ord.begin(),ord.end(),[&](int i,int j){return make_pair(v[i],-i)>make_pair(v[j],-j);});
return ord;
}
template<typename T> vector<T> inv_perm(const vector<T>&ord){
vector<T>inv(ord.size());
for(int i=0;i<ord.size();i++)inv[ord[i]] = i;
return inv;
}
ll FLOOR(ll n,ll div){assert(div>0);return n>=0?n/div:(n-div+1)/div;}
ll CEIL(ll n,ll div){assert(div>0);return n>=0?(n+div-1)/div:n/div;}
ll digitsum(ll n){ll ret=0;while(n){ret+=n%10;n/=10;}return ret;}
ll modulo(ll n,ll d){return (n%d+d)%d;};
template<typename T>T min(const vector<T>&v){return *min_element(v.begin(),v.end());}
template<typename T>T max(const vector<T>&v){return *max_element(v.begin(),v.end());}
template<typename T>T acc(const vector<T>&v){return accumulate(v.begin(),v.end(),T(0));};
template<typename T>T reverse(const T &v){return T(v.rbegin(),v.rend());};
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int popcount(ll x){return __builtin_popcountll(x);};
int poplow(ll x){return __builtin_ctzll(x);};
int pophigh(ll x){return 63 - __builtin_clzll(x);};
template<typename T>T poll(queue<T> &q){auto ret=q.front();q.pop();return ret;};
template<typename T>T poll(priority_queue<T> &q){auto ret=q.top();q.pop();return ret;};
template<typename T>T poll(QP<T> &q){auto ret=q.top();q.pop();return ret;};
template<typename T>T poll(stack<T> &s){auto ret=s.top();s.pop();return ret;};
ll MULT(ll x,ll y){if(LLONG_MAX/x<=y)return LLONG_MAX;return x*y;}
ll POW2(ll x, ll k){ll ret=1,mul=x;while(k){if(mul==LLONG_MAX)return LLONG_MAX;if(k&1)ret=MULT(ret,mul);mul=MULT(mul,mul);k>>=1;}return ret;}
ll POW(ll x, ll k){ll ret=1;for(int i=0;i<k;i++){if(LLONG_MAX/x<=ret)return LLONG_MAX;ret*=x;}return ret;}
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
std::ostream::sentry s(dest);
if (s) {
__uint128_t tmp = value < 0 ? -value : value;
char buffer[128];
char *d = std::end(buffer);
do {
--d;
*d = "0123456789"[tmp % 10];
tmp /= 10;
} while (tmp != 0);
if (value < 0) {
--d;
*d = '-';
}
int len = std::end(buffer) - d;
if (dest.rdbuf()->sputn(d, len) != len) {
dest.setstate(std::ios_base::badbit);
}
}
return dest;
}
namespace converter{
int dict[500];
const string lower="abcdefghijklmnopqrstuvwxyz";
const string upper="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string digit="0123456789";
const string digit1="123456789";
void regi_str(const string &t){
for(int i=0;i<t.size();i++){
dict[t[i]]=i;
}
}
void regi_int(const string &t){
for(int i=0;i<t.size();i++){
dict[i]=t[i];
}
}
vector<int>to_int(const string &s,const string &t){
regi_str(t);
vector<int>ret(s.size());
for(int i=0;i<s.size();i++){
ret[i]=dict[s[i]];
}
return ret;
}
vector<int>to_int(const string &s){
auto t=s;
sort(t.begin(),t.end());
t.erase(unique(t.begin(),t.end()),t.end());
return to_int(s,t);
}
vector<vector<int>>to_int(const vector<string>&s,const string &t){
regi_str(t);
vector<vector<int>>ret(s.size(),vector<int>(s[0].size()));
for(int i=0;i<s.size();i++){
for(int j=0;j<s[0].size();j++){
ret[i][j]=dict[s[i][j]];
}
}
return ret;
}
vector<vector<int>>to_int(const vector<string>&s){
string t;
for(int i=0;i<s.size();i++){
t+=s[i];
}
sort(t.begin(),t.end());t.erase(unique(t.begin(),t.end()),t.end());
return to_int(s,t);
}
string to_str(const vector<int>&s,const string &t){
regi_int(t);
string ret;
for(auto z:s)ret+=dict[z];
return ret;
}
vector<string> to_str(const vector<vector<int>>&s,const string &t){
regi_int(t);
vector<string>ret(s.size());
for(int i=0;i<s.size();i++){
for(auto z:s[i])ret[i]+=dict[z];
}
return ret;
}
}
template< typename T = int >
struct edge {
int to;
T cost;
int id;
edge():to(-1),id(-1){};
edge(int to, T cost = 1, int id = -1):to(to), cost(cost), id(id){}
operator int() const { return to; }
};
template<typename T>
using Graph = vector<vector<edge<T>>>;
template<typename T>
Graph<T>revgraph(const Graph<T> &g){
Graph<T>ret(g.size());
for(int i=0;i<g.size();i++){
for(auto e:g[i]){
int to = e.to;
e.to = i;
ret[to].push_back(e);
}
}
return ret;
}
template<typename T>
Graph<T> readGraph(int n,int m,int indexed=1,bool directed=false,bool weighted=false){
Graph<T> ret(n);
for(int es = 0; es < m; es++){
int u,v;
T w=1;
cin>>u>>v;u-=indexed,v-=indexed;
if(weighted)cin>>w;
ret[u].emplace_back(v,w,es);
if(!directed)ret[v].emplace_back(u,w,es);
}
return ret;
}
template<typename T>
Graph<T> readParent(int n,int indexed=1,bool directed=true){
Graph<T>ret(n);
for(int i=1;i<n;i++){
int p;cin>>p;
p-=indexed;
ret[p].emplace_back(i);
if(!directed)ret[i].emplace_back(p);
}
return ret;
}
}
using namespace template_tute;
template<typename T>
struct HLD{
using D=long long;
int n;
vector<int>sz;//部分木サイズ
vector<D>dep;
vector<int>par;
vector<int>head;
Graph<T> &g;//隣接リスト
vector<edge<T>>edges;//データ構造に乗せるedge列
vector<int>in,out;//[in,out)で部分木、[ina,inb]でa~bのパス(aが上)
vector<int>comp;//連結成分の根
//inは頂点のindexを表す。また、edge列の下側の頂点である
HLD(Graph<T> &g,int r=-1):g(g),n(g.size()){
hld_build(r);
}
void hld_build(int root = -1){
in.assign(n,-1);out.assign(n,-1);dep.assign(n,0);
par.assign(n,-1);head.assign(n,-1);sz.assign(n,-1);comp.assign(n,-1);
edges.assign(n,edge<T>());
if(root == -1){//根がどこでも良い場合(森でも可)
for(int i=0;i<n;i++){
if(sz[i] == -1){
head[i] = i;
dfs_sz(i, 0, i);
dfs_hld(i);
}
}
}
else{
head[root] = root;
dfs_sz(root, 0, root);
dfs_hld(root);
}
}
void dfs_sz(int k, D d,int r){
sz[k] = 1;
comp[k] = r;
dep[k] = d;
for(auto &e: g[k]){
if(e.to == par[k])continue;
par[e.to] = k;
dfs_sz(e.to, d+e.cost, r);
sz[k] += sz[e.to];
if(g[k][0].to==par[k]||sz[e.to] > sz[g[k][0].to])swap(e, g[k][0]);
}
}
int time = 0;
void dfs_hld(int k){
in[k] = time++;
for(auto e:g[k]){
if(e.to == par[k])continue;
head[e.to] = (e.to == g[k][0].to ? head[k]: e.to);
edges[time] = e;
dfs_hld(e.to);
}
out[k] = time;
}
int lca(int p,int q){
while(1){
if(in[p] < in[q])swap(p,q);
if(head[p] == head[q])return q;
p = par[head[p]];
}
}
vector<pair<int,int>>query_path(int p,int q,bool isEdge){
int r=lca(p,q);
vector<pair<int,int>>ret;
for(int i=0;i<2;i++){
if(i == 1)swap(p,q);
while(1){
if(isEdge&&p==r)break;
if(head[p]==head[r]){
ret.emplace_back(in[r]+(isEdge?1:i),in[p]+1);
break;
}
ret.emplace_back(in[head[p]],in[p]+1);
p = par[head[p]];
}
}
return ret;
}
vector<vector<pair<int,int>>>query_order_path(int p,int q,bool isEdge){
//非可換クエリ用、配列0を順番を反転したデータ構造に、配列1を通常のデータ構造に
vector<vector<pair<int,int>>>ret(2);
int r=lca(p,q);
for(int i=0;i<2;i++){
if(i == 1)swap(p,q);
while(1){
if(isEdge&&p==r)break;
if(head[p]==head[r]){
if(i==0) ret[i].emplace_back(n-(in[p]+1),n-(in[r]+(isEdge?1:i)));
else ret[i].emplace_back(in[r]+(isEdge?1:i),in[p]+1);
break;
}
if(i==0) ret[i].emplace_back(n-(in[p]+1),n-(in[head[p]]));
else ret[i].emplace_back(in[head[p]],in[p]+1);
p = par[head[p]];
}
}
reverse(ret[1].begin(), ret[1].end());
return ret;
}
pair<int,int>query_subtree(int p,bool isEdge){
return make_pair(in[p]+isEdge,out[p]);
}
//uのv方向の子 子孫関係は前もって確認すること(in,outを見る)
int child(int u,int v)const{
while(1){
if(head[u]==head[v]){
v=g[u][0].to;
break;
}
v=head[v];
if(par[v]==u)break;
v=par[v];
}
return v;
}
//uをv方向に一つ進めた頂点
int move(int u,int v)const{
assert(u!=v);
if(in[u]<in[v]&&in[v]<out[u])return child(u,v);
else return par[u];
}
D dist(int u,int v){
return dep[u]+dep[v]-2*dep[lca(u,v)];
}
vector<int>rev_in;
int climb(int u,int k){
if(rev_in.empty()){
rev_in.resize(n);
for(int i=0;i<n;i++)rev_in[in[i]]=i;
}
int nd=max<int>(dep[u]-k, 0);
while(dep[u]>nd){
if(dep[head[u]]>nd){
u=par[head[u]];
}
else{
u=rev_in[in[head[u]]+nd-dep[head[u]]];
}
}
return u;
}
int jump(int from,int to, int k){
int r = lca(from, to);
int d1 = dep[from] - dep[r];
int d2 = dep[to] - dep[r];
if(d1 + d2 < k)return -1;
else if(k <= d1)return climb(from, k);
else return climb(to, d1 + d2 - k);
}
template<typename I>
Graph<T>lca_tree(vector<I>&v){
auto compare=[&](int x,int y){return in[x]<in[y];};
sort(v.begin(),v.end(),compare);
int sz1=v.size();
for(int i=0;i<sz1-1;i++)v.push_back(lca(v[i],v[i+1]));
sort(v.begin(),v.end(),compare);
v.erase(unique(v.begin(),v.end()),v.end());
int sz2=v.size();
Graph<T>ret(sz2);
stack<int>st;
for(int i=0;i<sz2;i++){
while(!st.empty()&&out[v[st.top()]]<=in[v[i]])st.pop();
if(!st.empty()){
ret[st.top()].emplace_back(i,dep[v[i]]-dep[v[st.top()]]);
ret[i].emplace_back(st.top(),dep[v[i]]-dep[v[st.top()]]);
}
st.push(i);
}
return ret;
}
};
template< int mod >
struct ModInt {
int x;
ModInt() : x(0) {}
ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
ModInt &operator+=(const ModInt &p) {
if((x += p.x) >= mod) x -= mod;
return *this;
}
ModInt &operator-=(const ModInt &p) {
if((x += mod - p.x) >= mod) x -= mod;
return *this;
}
ModInt &operator*=(const ModInt &p) {
x = (int) (1LL * x * p.x % mod);
return *this;
}
ModInt &operator/=(const ModInt &p) {
*this *= p.inverse();
return *this;
}
ModInt operator-() const { return ModInt(-x); }
friend ModInt operator+(const ModInt& lhs, const ModInt& rhs) {
return ModInt(lhs) += rhs;
}
friend ModInt operator-(const ModInt& lhs, const ModInt& rhs) {
return ModInt(lhs) -= rhs;
}
friend ModInt operator*(const ModInt& lhs, const ModInt& rhs) {
return ModInt(lhs) *= rhs;
}
friend ModInt operator/(const ModInt& lhs, const ModInt& rhs) {
return ModInt(lhs) /= rhs;
}
bool operator==(const ModInt &p) const { return x == p.x; }
bool operator!=(const ModInt &p) const { return x != p.x; }
ModInt inverse() const {
int a = x, b = mod, u = 1, v = 0, t;
while(b > 0) {
t = a / b;
swap(a -= t * b, b);
swap(u -= t * v, v);
}
return ModInt(u);
}
ModInt pow(int64_t n) const {
ModInt ret(1), mul(x);
while(n > 0) {
if(n & 1) ret *= mul;
mul *= mul;
n >>= 1;
}
return ret;
}
pair<int,int>frac(){
for(int j=1;j<=300;j++){
for(int i=-300;i<=300;i++){
if(ModInt(i)/j==*this){
return make_pair(i,j);
}
}
}
return make_pair(-1,-1);
}
friend ostream &operator<<(ostream &os, const ModInt &p) {
return os << p.x;
}
friend istream &operator>>(istream &is, ModInt &a) {
int64_t t;
is >> t;
a = ModInt< mod >(t);
return (is);
}
static constexpr int get_mod() { return mod; }
};
template< typename T >
struct Combination {
vector< T > _fact, _rfact, _inv;
Combination(ll sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) {
_fact[0] = _rfact[sz] = _inv[0] = 1;
for(ll i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i;
_rfact[sz] /= _fact[sz];
for(ll i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1);
for(ll i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1];
}
inline T fact(ll k) const { return _fact[k]; }
inline T rfact(ll k) const { return _rfact[k]; }
inline T inv(ll k) const { return _inv[k]; }
T P(ll n, ll r) const {
if(r < 0 || n < r) return 0;
return fact(n) * rfact(n - r);
}
T C(ll p, ll q) const {
if(q < 0 || p < q) return 0;
return fact(p) * rfact(q) * rfact(p - q);
}
T RC(ll p, ll q) const {
if(q < 0 || p < q) return 0;
return rfact(p) * fact(q) * fact(p - q);
}
T H(ll n, ll r) const {
if(n < 0 || r < 0) return (0);
return r == 0 ? 1 : C(n + r - 1, r);
}
//+1がm個、-1がn個で prefix sumが常にk以上
T catalan(ll m,ll n,ll k){
if(n>m-k)return 0;
else return C(n+m,m)-C(n+m,n+k-1);
}
};
using modint = ModInt< MOD9 >;modint mpow(ll n, ll x){return modint(n).pow(x);}modint mpow(modint n, ll x){return n.pow(x);}
//using modint=ld;modint mpow(ll n, ll x){return pow(n,x);}modint mpow(modint n, ll x){return pow(n,x);}
using Comb=Combination<modint>;
template< typename sum_t, typename key_t >
struct ReRooting {
struct Edge {
int to;
key_t data;
sum_t dp, ndp;
};
using F = function< sum_t(sum_t, sum_t) >;
using G = function< sum_t(sum_t, key_t) >;
vector< vector< Edge > > g;
vector< sum_t > subdp, dp;
vector< sum_t > init;
const sum_t ident;
const F f;
const G gg;
ReRooting(int V, const F f, const G g, const sum_t &ident)
: g(V), f(f), gg(g), ident(ident), subdp(V, ident), dp(V, ident), init(V, ident) {}
void add_edge(int u, int v, const key_t &d) {
g[u].emplace_back((Edge) {v, d, ident, ident});
g[v].emplace_back((Edge) {u, d, ident, ident});
}
void add_edge_bi(int u, int v, const key_t &d, const key_t &e) {
g[u].emplace_back((Edge) {v, d, ident, ident});
g[v].emplace_back((Edge) {u, e, ident, ident});
}
void set(int idx, sum_t s){
subdp[idx] = s;
init[idx] = s;
}
void dfs_sub(int idx, int par) {
for(auto &e : g[idx]) {
if(e.to == par) continue;
dfs_sub(e.to, idx);
subdp[idx] = f(subdp[idx], gg(subdp[e.to], e.data));
}
}
void dfs_all(int idx, int par, const sum_t &top) {
sum_t buff{init[idx]};
for(int i = 0; i < (int) g[idx].size(); i++) {
auto &e = g[idx][i];
e.ndp = buff;
e.dp = gg(par == e.to ? top : subdp[e.to], e.data);
buff = f(buff, e.dp);
}
dp[idx] = buff;
buff = ident;
for(int i = (int) g[idx].size() - 1; i >= 0; i--) {
auto &e = g[idx][i];
if(e.to != par) dfs_all(e.to, idx, f(e.ndp, buff));
e.ndp = f(e.ndp, buff);
buff = f(buff, e.dp);
}
}
vector< sum_t > build() {
dfs_sub(0, -1);
dfs_all(0, -1, ident);
return dp;
}
};
template<typename T>
struct BIT{
ll n;
ll k=1;
vector<T>data;
BIT() = default;
BIT(ll size):n(size){
data.assign(n,0);
while(k*2<=n)k*=2;
}
void add(ll a,T w){
assert(0<=a);
for(ll i=a+1;i<=n;i+=i&-i)data[i-1]+=w;
}
T sum(ll a){//[0,a)
if(a<=0)return 0;
T ret = 0;
for(ll i=a;i>0;i-=i&-i)ret+=data[i-1];
return ret;
}
//[a,b)
T sum(ll a,ll b){return a>=b?0:sum(b)-sum(a);}
T operator[](ll pos){
return sum(pos,pos+1);
}
ll lower_bound(ll x){
ll ret=0;
for(ll i=k;i>0;i/=2){
if(ret+i<=n&&data[ret+i-1]<x){
x-=data[ret+i-1];
ret+=i;
}
}
return ret;
}
ll lower_first(ll x){
return lower_bound(sum(n)-x+1);
}
void print(){
for(ll i=0;i<n;i++){
if(i!=0)cout<<" ";
cout<<(*this)[i];
}
cout<<endl;
}
};
void solve(){
ll res=0,buf=0;
bool judge = true;
ll n,q;cin>>n>>q;
auto g=readParent<int>(n);
HLD<int> hld(g);
using PM=pair<modint,modint>;
auto f=[&](PM p,PM q)->PM
{return PM(p.fi*q.fi,p.se+q.se);};
auto gg=[&](PM p,int x)->PM {
return PM(1+p.fi,p.fi+p.se);
};
ReRooting<PM,int>rr(n,f,gg,PM(1,0));
rep(i,0,n){
for(auto to:g[i]){
if(i<to){
rr.add_edge(i,to,1);
}
}
}
rep(i,0,n){
rr.set(i,PM(1,0));
}
auto vv=rr.build();
BIT<modint>bv(n),be(n);
vector<modint> dec(n);
rep(i,0,n){
for(auto dat:rr.g[i]){
if(i<dat.to){
be.add(hld.in[dat.to],dat.dp.se);
bv.add(hld.in[i],dat.dp.se);
}
else{
dec[i]+=dat.dp.se;
}
}
}
//OUT(vv);
//OUT(dec);
//be.print();bv.print();
while(q--){
ll u,v;cin>>u>>v;u--;v--;
modint all=vv[0].fi+vv[0].se;
{
auto tmp=hld.query_path(u,v,false);
for(auto z:tmp){
all-=bv.sum(z.fi,z.se);
}
}
{
auto tmp=hld.query_path(u,v,true);
for(auto z:tmp){
all+=be.sum(z.fi,z.se);
}
}
all-=dec[hld.lca(u,v)];
cout<<all<<endl;
}
}
int main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
ll res=0,buf=0;
bool judge = true;
int T = 1;
cin>>T;
while(T--){
solve();
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3628kb
input:
2 3 2 1 1 2 3 1 2 5 3 1 1 2 2 4 5 2 4 2 3
output:
6 5 14 13 15
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 209ms
memory: 3644kb
input:
3000 98 100 1 2 1 3 5 3 2 5 5 4 3 7 12 10 12 8 10 4 4 3 10 14 11 11 22 23 14 20 29 1 18 7 12 29 20 29 12 21 6 20 3 25 7 21 16 44 38 44 7 11 5 24 34 24 41 48 56 58 56 3 26 55 62 33 9 38 63 39 3 67 14 24 60 35 1 22 74 36 57 61 55 46 44 12 16 60 44 50 22 58 78 15 57 57 75 88 15 43 28 67 66 3 39 6 19 84...
output:
964062690 949799024 949777463 964050185 119859605 949794873 949799267 964064991 836980963 964045750 964065023 959849545 536098301 964045791 964064966 964046253 964052677 949782329 964050627 949794848 188617843 964065041 2617316 949782330 964046253 536098346 949777935 964052584 949777939 964046254 94...
result:
ok 300000 lines
Test #3:
score: 0
Accepted
time: 246ms
memory: 3852kb
input:
300 998 1000 1 2 1 3 3 2 2 8 5 2 8 8 12 3 13 3 7 8 16 14 10 22 10 1 24 17 16 1 16 21 2 23 2 1 20 11 1 1 22 19 5 15 10 37 15 39 13 16 33 37 37 36 37 16 3 45 10 28 14 4 16 17 55 6 6 5 31 67 51 35 47 48 10 16 75 21 45 71 28 64 39 9 37 5 65 79 28 84 29 79 21 50 21 16 93 72 58 35 30 14 86 90 60 65 33 47 ...
output:
327306708 121504060 970333956 71256467 492200713 164920447 56359491 54857868 62271655 175858304 373532115 138628785 54854112 616763633 41337286 837501264 861536431 572242958 417784906 22152900 460075855 89587278 985881197 291627546 96610921 437457168 101307362 180803897 373532108 80109336 837492247 ...
result:
ok 300000 lines
Test #4:
score: 0
Accepted
time: 276ms
memory: 39396kb
input:
3 100000 100000 1 1 2 4 2 4 6 5 1 8 9 7 12 10 7 12 10 4 9 7 6 22 10 5 18 3 8 18 5 20 12 26 10 11 14 5 28 29 33 12 5 10 30 21 36 24 1 26 39 29 2 42 40 33 41 39 23 2 50 11 47 61 61 52 3 27 65 4 24 1 15 41 68 5 62 1 44 60 44 79 68 6 53 72 21 58 66 24 54 78 29 39 75 74 13 52 71 35 40 85 47 19 60 44 101 ...
output:
174648911 988966670 586060443 352691812 610467698 718056854 353397034 944134980 945506609 743772159 17398768 898225958 509929535 581516662 124983919 679181027 890516256 792976265 81256963 846568565 990778256 394490295 307247131 281874314 78565559 438162317 218440246 677940950 608561943 237178689 748...
result:
ok 300000 lines
Test #5:
score: 0
Accepted
time: 294ms
memory: 39384kb
input:
3 100000 100000 1 2 3 2 2 3 4 3 7 6 10 8 6 4 3 6 5 8 3 17 2 7 1 1 17 3 4 11 25 26 5 7 2 20 2 32 35 11 9 39 16 42 26 43 29 22 35 18 3 34 45 19 27 3 41 27 10 14 4 4 45 53 35 49 57 37 24 43 68 6 44 5 15 12 62 22 11 26 37 41 8 73 56 76 78 9 46 14 81 67 49 12 74 15 16 69 86 48 47 77 58 77 87 54 79 80 99 ...
output:
761112418 717651384 861477152 134730845 623546487 488508714 852403783 522543884 880846196 809656417 876270841 575462796 111884802 845956357 990889899 222833220 7564761 917539269 355409810 261089607 166264493 612109684 526575279 410009284 848925228 885468503 90907188 969960703 663719627 309794696 503...
result:
ok 300000 lines
Test #6:
score: 0
Accepted
time: 110ms
memory: 25044kb
input:
3 100000 100000 1 2 1 2 3 5 1 4 2 6 10 3 10 6 13 14 4 18 13 4 21 19 9 16 14 5 13 15 10 29 11 4 33 31 25 15 19 32 12 17 22 24 35 38 3 1 46 28 16 8 13 5 46 44 25 49 37 30 47 37 10 56 32 29 36 7 13 47 11 2 24 6 51 65 36 52 15 74 62 65 25 34 35 61 12 4 20 81 64 39 21 79 90 29 68 30 7 34 60 1 1 1 1 1 1 1...
output:
47613014 867989885 314355471 515168737 161160818 552527 328577529 705173752 262933227 431743363 481168259 545043565 319743713 655278418 20733052 900938971 104104163 575553196 635937653 545910595 298966873 864807486 817091004 10697715 66840685 327639210 80580410 489368876 303238352 545043565 26533356...
result:
ok 300000 lines
Test #7:
score: 0
Accepted
time: 333ms
memory: 25444kb
input:
10000 10 10 1 2 2 4 4 3 4 7 9 5 4 6 7 1 9 9 5 2 2 2 1 4 5 5 5 4 6 7 6 10 10 1 1 2 4 3 4 7 5 6 10 7 7 5 10 2 10 1 4 6 1 4 1 9 8 9 4 2 10 5 9 9 1 2 1 4 2 5 2 5 5 6 9 4 4 4 3 4 6 9 8 2 7 9 9 4 1 3 10 10 1 1 2 4 4 2 7 6 1 2 10 3 10 2 6 8 3 4 8 5 6 8 5 3 6 6 10 4 7 9 9 1 2 1 3 5 2 5 2 7 8 9 6 7 2 2 3 2 6...
output:
89 106 100 108 90 91 89 45 89 106 71 58 60 50 68 63 66 60 59 71 72 55 50 68 73 57 46 55 63 110 90 113 113 114 99 115 118 118 113 83 83 73 77 82 57 82 57 83 90 91 92 92 91 59 91 93 88 66 79 69 80 72 66 66 63 33 171 169 169 170 106 160 159 157 168 169 56 91 23 95 86 80 87 91 92 89 40 34 41 37 31 37 33...
result:
ok 290206 lines
Test #8:
score: 0
Accepted
time: 178ms
memory: 40928kb
input:
10000 9 9 1 2 2 4 2 5 1 7 1 2 4 7 5 6 5 7 7 4 8 5 5 8 7 4 8 5 10 10 1 2 1 1 5 2 1 7 3 5 3 5 9 5 6 10 9 3 5 2 6 6 6 8 10 7 7 6 6 10 10 1 1 2 4 5 1 2 3 7 3 5 4 7 5 9 7 8 1 3 5 8 1 9 6 9 8 6 7 10 10 10 1 2 3 1 1 1 3 3 2 1 1 3 10 10 6 4 10 4 10 3 2 8 9 6 8 6 3 8 9 10 10 1 2 1 3 4 6 3 7 5 10 6 10 7 3 6 5...
output:
62 57 68 44 57 70 70 57 70 133 134 83 123 133 132 42 133 80 42 96 94 97 92 83 86 84 98 87 57 152 171 172 172 172 170 154 180 179 154 63 65 60 30 46 49 42 63 62 54 97 110 98 114 114 115 98 110 112 112 170 171 170 158 160 170 171 79 169 160 74 74 77 73 75 76 26 76 112 110 112 100 112 91 99 99 58 99 36...
result:
ok 290080 lines
Test #9:
score: 0
Accepted
time: 190ms
memory: 24516kb
input:
10000 9 9 1 2 3 1 3 6 3 6 2 1 9 1 7 9 7 7 6 6 2 7 6 8 3 6 4 6 10 10 1 1 3 3 5 2 7 3 6 8 7 4 9 3 10 10 8 9 4 5 1 9 9 4 6 8 5 4 2 9 9 1 1 2 4 4 5 4 4 5 2 9 8 2 2 8 1 3 5 6 1 9 3 2 8 4 6 8 8 1 2 3 1 2 5 2 1 6 8 4 7 1 8 4 8 3 7 3 8 1 1 5 9 9 1 2 1 3 5 3 7 1 7 2 6 3 4 3 7 7 9 7 4 4 4 4 8 6 4 4 10 10 1 1 ...
output:
65 90 70 35 68 88 85 84 85 39 82 86 96 82 87 41 86 93 88 101 98 75 102 104 102 103 100 97 52 52 42 52 51 56 52 41 61 57 64 38 66 23 23 60 23 87 116 86 115 118 136 87 135 129 115 123 130 82 120 82 119 120 133 132 129 85 89 87 90 41 85 86 45 63 53 48 23 46 35 45 47 41 36 58 64 62 62 61 67 20 69 56 56 ...
result:
ok 289972 lines
Test #10:
score: 0
Accepted
time: 190ms
memory: 32784kb
input:
10000 9 9 1 2 2 1 2 3 1 1 3 3 3 3 2 7 8 2 3 5 1 1 9 2 3 1 7 5 8 8 1 1 2 4 5 1 7 6 6 6 2 4 8 4 7 2 4 8 7 2 1 6 5 9 9 1 2 2 2 1 4 2 1 5 2 3 1 8 5 8 2 1 5 7 2 2 5 4 3 8 1 9 9 1 2 1 4 4 4 2 8 5 7 1 2 7 7 7 4 9 2 7 7 8 2 3 6 8 5 9 9 1 1 2 4 3 6 7 5 2 2 7 8 3 5 7 2 6 4 7 3 5 9 6 6 2 7 10 10 1 2 1 2 4 6 6 ...
output:
74 74 111 117 119 104 117 118 120 10 34 40 39 31 23 34 19 121 125 122 121 125 123 121 123 125 66 69 33 65 63 33 62 79 80 24 17 38 38 39 29 17 21 38 66 74 70 50 68 69 45 70 45 81 95 103 96 100 75 75 75 61 100 91 87 92 92 86 43 55 86 82 80 95 100 102 49 25 108 71 94 104 89 92 98 91 94 93 96 63 63 98 6...
result:
ok 289954 lines
Test #11:
score: 0
Accepted
time: 258ms
memory: 41184kb
input:
10000 9 9 1 1 3 1 4 3 5 7 7 7 7 6 2 3 2 6 2 7 4 1 6 5 6 7 6 7 8 8 1 1 2 1 5 6 2 8 2 8 3 1 1 6 8 1 4 2 8 3 5 8 4 8 8 1 2 1 4 3 1 5 3 2 5 5 7 8 4 4 6 7 2 8 2 1 1 3 9 9 1 2 3 2 3 3 3 7 9 9 4 4 4 3 9 9 8 6 3 8 6 1 1 1 7 6 8 8 1 1 3 3 2 2 1 4 1 7 1 4 7 2 8 2 2 8 5 4 8 1 5 10 10 1 2 2 3 4 2 3 6 7 3 5 10 3...
output:
44 68 70 73 72 71 74 68 68 37 46 40 50 45 37 44 38 29 20 39 27 39 41 35 37 42 61 121 42 122 121 126 51 123 55 55 60 55 44 56 56 55 101 127 51 83 127 125 127 131 123 127 44 132 135 118 79 136 128 137 137 128 112 92 99 92 111 108 106 106 114 112 55 56 51 60 55 54 55 56 52 22 42 53 31 44 45 45 50 45 40...
result:
ok 289847 lines
Test #12:
score: 0
Accepted
time: 264ms
memory: 25080kb
input:
10000 8 8 1 1 3 3 1 4 2 2 5 1 3 7 1 2 7 7 8 1 6 5 6 4 4 8 8 1 2 1 3 4 6 5 4 3 5 3 6 4 6 4 5 5 2 8 4 8 7 2 9 9 1 2 3 3 1 2 3 4 5 6 1 3 2 8 5 2 7 5 6 1 8 3 8 5 2 8 9 9 1 1 1 2 4 6 3 3 3 9 6 2 6 5 6 3 6 6 4 5 4 5 9 4 3 4 8 8 1 1 3 4 2 5 1 1 2 7 2 4 2 8 3 1 7 5 1 2 4 3 6 9 9 1 2 1 4 5 1 3 5 9 6 1 9 7 4 ...
output:
51 48 51 53 54 43 50 30 30 20 20 20 14 26 33 30 94 92 91 91 92 55 85 86 91 53 67 68 69 34 66 66 68 67 32 42 39 35 40 39 39 37 42 58 54 50 49 42 61 51 53 18 88 68 78 85 36 81 63 24 84 28 40 31 39 38 24 38 30 84 73 75 57 82 78 57 65 84 68 70 53 70 53 67 68 50 71 74 72 23 31 45 66 73 65 22 108 101 102 ...
result:
ok 290127 lines
Test #13:
score: 0
Accepted
time: 265ms
memory: 33164kb
input:
10000 9 9 1 1 3 2 3 1 1 3 9 8 3 9 5 8 1 9 6 4 7 3 2 2 8 8 2 5 9 9 1 2 1 3 5 4 7 6 9 5 2 3 6 1 4 1 2 9 1 1 8 5 5 8 5 1 9 9 1 1 2 1 4 1 1 2 8 3 9 1 4 6 6 1 9 4 1 9 7 6 3 3 9 2 8 8 1 2 3 2 1 3 1 5 6 8 5 6 7 3 6 2 8 2 7 4 2 5 3 9 9 1 1 3 1 2 6 1 2 2 1 1 4 5 9 1 4 3 6 6 9 7 4 7 7 5 4 8 8 1 2 1 3 5 2 4 3 ...
output:
118 105 112 117 106 117 74 55 75 24 29 38 27 35 24 42 42 36 114 119 71 121 105 119 122 57 103 56 56 60 59 55 55 55 55 90 87 92 87 94 81 96 28 88 38 38 21 37 21 44 35 21 37 42 48 33 46 42 48 14 39 32 95 97 39 78 94 63 96 106 86 34 100 104 97 85 99 113 106 71 47 65 70 67 39 60 63 64 60 74 53 60 52 60 ...
result:
ok 289926 lines
Test #14:
score: 0
Accepted
time: 182ms
memory: 40680kb
input:
10000 8 8 1 2 1 2 4 2 7 4 5 2 6 5 8 1 1 7 7 6 5 2 1 4 4 10 10 1 1 2 2 5 6 5 3 6 3 8 10 8 8 3 9 3 5 5 1 1 7 2 2 9 7 2 2 10 8 8 1 1 1 1 3 3 6 5 7 8 8 4 5 4 4 5 2 4 2 4 2 3 3 9 9 1 1 1 4 5 6 6 5 1 3 1 3 6 3 9 3 3 6 1 2 5 9 8 5 8 1 8 8 1 2 1 3 5 3 6 1 5 7 3 5 2 5 7 1 5 1 3 5 5 5 7 9 9 1 2 3 1 2 1 7 2 7 ...
output:
54 54 52 39 34 55 51 28 104 96 104 49 90 69 103 94 103 103 64 20 58 29 58 58 58 54 49 49 74 71 74 49 61 65 74 40 33 38 36 40 37 27 36 93 87 94 79 90 28 93 88 93 52 43 49 45 45 43 31 54 48 52 31 22 53 52 50 46 104 107 100 94 102 96 108 105 104 96 112 92 115 94 93 62 111 92 107 62 32 44 44 33 42 23 44...
result:
ok 289769 lines
Test #15:
score: 0
Accepted
time: 186ms
memory: 40592kb
input:
10000 8 8 1 2 1 3 4 6 4 1 8 8 5 7 7 5 4 1 6 3 1 8 7 1 8 9 9 1 2 3 2 5 1 7 4 4 8 9 6 3 9 4 8 4 7 3 9 5 2 6 1 2 6 8 8 1 2 2 4 2 4 6 6 5 1 1 8 4 2 6 7 4 7 8 1 2 1 6 9 9 1 1 1 4 4 2 1 5 2 7 1 4 4 4 8 3 5 2 6 7 2 6 7 6 6 9 10 10 1 1 2 1 1 4 3 2 6 3 7 2 5 10 9 3 5 5 7 1 7 1 10 1 9 8 3 3 6 9 9 1 1 3 2 5 3 ...
output:
35 41 12 40 36 33 34 35 59 57 42 59 58 42 50 54 51 67 31 67 62 53 68 61 63 59 90 78 86 94 94 93 94 82 137 133 136 129 136 135 129 133 87 130 78 78 71 64 80 65 64 71 65 164 168 165 164 164 167 167 167 166 163 36 40 36 37 37 37 39 38 95 92 92 86 94 57 92 87 90 80 29 57 55 60 59 57 51 57 54 64 39 59 64...
result:
ok 290030 lines
Test #16:
score: 0
Accepted
time: 201ms
memory: 32888kb
input:
10000 8 8 1 2 1 4 5 6 7 8 8 7 5 3 5 5 5 8 4 4 6 1 7 1 2 8 8 1 1 3 3 2 5 4 4 3 7 1 8 5 6 3 2 8 5 7 4 4 2 8 8 8 1 1 1 3 1 4 2 2 5 7 1 7 8 5 6 5 8 4 8 7 8 7 1 9 9 1 1 2 3 2 2 1 7 6 6 7 6 4 7 3 5 7 9 8 6 2 5 6 4 4 2 9 9 1 2 3 3 2 5 2 5 8 5 8 5 6 6 9 6 3 1 4 2 4 7 7 5 9 7 8 8 1 2 3 4 4 2 1 3 8 3 5 5 2 3 ...
output:
8 25 30 20 30 27 32 20 38 42 41 42 44 27 26 44 59 57 60 58 60 59 60 57 43 87 87 55 59 92 93 86 85 103 103 45 104 99 99 96 77 78 44 40 46 42 43 48 33 49 62 66 45 45 31 70 62 64 67 34 80 86 78 75 48 86 80 84 82 71 64 70 69 68 63 58 68 62 138 145 154 156 151 114 157 151 113 158 51 31 51 22 49 51 50 44 ...
result:
ok 289869 lines
Test #17:
score: 0
Accepted
time: 333ms
memory: 25484kb
input:
10000 8 8 1 1 2 3 3 4 6 7 8 1 6 2 3 5 8 2 1 2 5 8 4 2 5 8 8 1 2 3 2 4 2 4 4 2 7 8 5 8 7 4 6 4 6 4 7 4 1 7 8 8 1 1 2 2 2 4 3 6 3 3 2 5 1 7 5 6 1 2 5 3 2 7 8 8 8 1 1 2 3 3 5 7 6 8 8 8 4 1 1 6 7 3 8 2 8 1 7 2 8 8 1 2 3 3 2 1 7 8 3 1 4 6 5 8 2 3 3 3 6 1 3 5 7 9 9 1 2 1 3 2 5 5 8 3 7 9 6 5 9 1 1 4 2 3 1 ...
output:
43 36 37 34 31 38 42 38 57 59 59 58 41 41 58 50 54 53 52 52 52 49 53 57 39 11 30 36 37 43 41 42 50 48 46 46 36 45 47 50 56 65 51 34 51 57 56 55 48 23 65 66 74 74 69 74 23 63 116 113 119 66 112 116 99 105 116 113 59 53 25 59 41 41 49 59 116 110 125 110 83 110 123 109 111 122 79 74 79 79 75 51 51 51 5...
result:
ok 289830 lines
Test #18:
score: 0
Accepted
time: 176ms
memory: 41004kb
input:
10000 8 8 1 2 2 4 3 3 4 4 7 7 7 5 1 4 7 6 4 3 6 3 1 2 6 10 10 1 1 1 4 1 5 3 1 9 10 10 4 9 9 2 3 3 8 1 7 1 4 8 1 10 8 7 3 9 8 8 1 2 2 2 5 6 5 6 5 1 8 8 6 3 5 4 8 8 7 2 1 3 7 8 8 1 2 2 4 4 3 3 8 6 1 7 2 6 1 6 8 3 3 2 3 2 8 4 8 8 1 2 2 1 2 3 2 8 1 7 6 5 7 8 5 1 5 1 2 2 2 3 3 8 8 1 1 1 2 3 6 4 6 6 1 4 1...
output:
59 23 56 59 59 45 55 55 50 149 147 98 147 150 150 147 153 148 56 64 57 63 64 58 57 66 60 56 55 56 45 54 54 59 75 76 78 76 51 74 72 50 22 38 39 44 43 39 22 27 41 21 41 40 41 49 51 47 126 109 135 122 135 129 126 133 51 135 135 135 101 140 135 135 140 134 137 134 45 59 45 56 60 60 56 45 220 219 74 218 ...
result:
ok 290002 lines
Test #19:
score: 0
Accepted
time: 186ms
memory: 24364kb
input:
10000 10 10 1 2 1 1 3 5 6 6 1 5 9 1 3 6 6 1 5 8 10 9 5 9 9 5 10 3 4 9 8 10 10 1 1 3 4 1 1 1 2 9 5 2 1 1 4 1 7 1 7 2 9 4 9 2 3 4 7 10 7 3 10 10 1 2 3 3 4 3 7 3 7 2 2 2 3 2 10 8 6 9 1 10 4 1 6 7 5 4 2 9 6 8 8 1 2 3 1 5 4 5 2 7 1 8 8 7 1 3 2 3 7 5 1 4 5 6 8 8 1 1 3 2 1 4 4 2 2 8 5 8 1 2 6 3 7 5 2 2 3 5...
output:
102 95 60 86 101 102 31 87 96 62 137 128 133 129 132 138 101 101 135 132 122 182 187 188 184 187 186 185 184 184 30 30 40 32 27 39 34 25 26 49 46 39 40 27 43 14 57 66 64 54 62 38 59 67 59 110 113 75 75 111 112 75 111 113 83 97 23 93 95 94 83 86 86 84 156 144 159 69 156 159 143 156 145 73 168 165 168...
result:
ok 289994 lines
Test #20:
score: 0
Accepted
time: 199ms
memory: 32812kb
input:
10000 9 9 1 2 3 4 5 2 2 1 2 4 1 9 9 2 2 4 7 4 8 5 9 5 7 3 1 5 8 8 1 2 1 1 5 2 2 8 1 5 3 5 3 5 2 1 1 3 1 3 4 7 3 9 9 1 1 3 1 1 2 2 7 6 5 2 9 2 8 3 5 1 4 5 7 8 2 1 1 7 6 9 9 1 2 1 2 5 1 1 5 3 1 9 6 1 7 1 5 4 9 4 9 8 1 1 3 3 4 8 8 1 1 2 3 3 6 5 5 5 6 3 7 2 1 4 3 4 2 4 3 1 8 4 10 10 1 1 3 3 2 5 4 8 4 3 ...
output:
67 43 63 67 68 70 72 65 71 63 65 65 64 54 63 64 58 86 81 79 87 87 93 79 84 93 99 78 89 102 104 104 89 99 100 26 38 44 33 42 23 39 45 90 94 97 97 87 47 96 96 69 90 114 118 110 110 119 121 120 114 119 82 43 51 31 44 46 16 52 52 68 33 66 70 71 70 37 71 57 51 51 52 34 18 18 49 73 64 74 66 61 70 49 65 75...
result:
ok 289988 lines
Test #21:
score: 0
Accepted
time: 262ms
memory: 41212kb
input:
10000 8 8 1 2 2 2 2 4 4 6 6 3 7 8 7 5 3 1 6 8 4 6 2 4 4 10 10 1 2 3 4 3 5 5 6 7 4 4 1 10 4 9 9 4 7 5 6 9 6 1 3 2 6 2 9 10 10 10 1 1 1 3 4 5 3 5 3 1 8 9 3 6 6 6 2 6 5 7 1 10 5 4 2 7 3 3 9 8 8 1 2 3 1 3 3 3 6 8 5 8 4 8 1 6 3 8 5 5 7 3 2 4 8 8 1 1 2 1 5 4 2 2 6 2 1 1 5 7 4 5 8 1 2 8 4 4 1 8 8 1 2 3 4 4...
output:
41 86 70 82 82 69 81 68 70 91 82 82 68 51 77 74 76 91 147 145 44 130 153 151 145 129 145 145 66 71 66 70 65 19 65 68 51 48 44 31 51 48 45 50 60 59 59 51 54 59 55 45 74 73 77 77 75 75 75 75 160 171 160 160 157 170 168 158 159 171 90 90 117 114 118 117 107 114 37 113 47 37 45 37 19 45 50 48 121 116 11...
result:
ok 290036 lines
Test #22:
score: 0
Accepted
time: 250ms
memory: 25028kb
input:
10000 9 9 1 2 2 1 2 2 7 3 8 1 6 1 2 4 4 4 2 7 6 5 2 9 9 9 1 9 9 9 1 1 3 1 5 6 5 7 9 5 3 5 7 5 1 3 4 6 7 4 6 6 8 1 8 7 8 8 1 1 3 2 1 5 1 2 1 5 5 4 7 5 2 1 1 7 5 2 5 1 6 10 10 1 1 2 1 5 3 2 7 4 10 3 5 6 4 10 9 3 3 3 4 6 7 7 4 7 9 3 7 7 9 9 1 2 2 4 3 2 1 7 7 8 4 6 9 7 4 3 8 3 2 1 8 6 8 3 2 5 9 9 1 1 2 ...
output:
113 111 109 55 110 112 111 38 113 62 64 61 56 68 70 45 63 62 51 28 57 41 48 29 41 49 96 59 55 69 66 95 46 97 69 46 86 86 57 85 86 83 87 86 84 48 68 63 54 20 68 17 61 65 69 49 49 25 70 69 66 60 66 105 112 68 117 117 116 69 113 113 115 49 45 47 48 45 48 39 40 160 169 172 159 169 170 171 171 169 160 79...
result:
ok 289982 lines
Test #23:
score: 0
Accepted
time: 247ms
memory: 32936kb
input:
10000 8 8 1 1 2 3 2 4 6 7 8 3 4 5 2 2 4 5 3 5 3 2 2 1 7 9 9 1 2 3 1 4 1 3 2 9 6 5 8 9 7 7 4 5 8 3 1 3 1 2 7 1 8 9 9 1 1 3 3 5 1 1 5 8 2 6 4 1 7 8 5 7 3 3 2 5 7 2 4 6 8 9 9 1 2 3 1 3 2 5 1 6 4 4 6 2 1 8 1 8 5 9 2 7 2 3 1 1 2 8 8 1 2 2 2 4 1 1 7 7 7 4 5 8 4 5 8 2 3 4 8 6 4 4 10 10 1 1 1 4 1 5 4 8 4 6 ...
output:
42 43 42 38 23 23 36 42 80 82 76 83 82 80 80 75 81 90 96 89 103 99 99 103 100 104 62 62 76 69 47 77 71 80 76 27 67 66 63 65 63 68 42 154 154 172 171 111 171 154 153 154 173 112 113 112 112 114 113 114 108 109 105 122 123 125 131 132 55 122 123 123 65 62 53 63 61 53 64 67 166 81 165 166 166 133 161 1...
result:
ok 289985 lines
Test #24:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
2 2 1 1 2 1 2 4 1 1 1 1 2 2 1 2 2
output:
3 2 3 3 2
result:
ok 5 lines
Test #25:
score: 0
Accepted
time: 177ms
memory: 40676kb
input:
10000 9 9 1 1 3 1 4 2 6 4 6 1 9 1 2 2 7 3 8 5 8 3 3 8 7 4 8 3 9 9 1 2 1 1 3 1 1 5 9 5 1 5 1 5 4 7 1 4 6 7 7 9 2 8 6 5 10 10 1 2 3 2 5 6 5 1 6 10 2 4 2 1 1 10 7 3 4 5 5 4 8 3 2 6 1 4 6 8 8 1 2 3 3 2 4 2 2 8 1 4 7 8 5 7 1 4 4 6 5 5 7 5 8 8 1 2 1 4 5 4 6 8 7 3 7 6 8 6 2 2 8 1 7 2 8 5 3 8 8 1 1 1 1 3 6 ...
output:
63 62 34 58 65 58 58 64 58 67 98 98 98 97 103 100 100 104 114 102 68 86 69 100 113 101 115 116 57 65 66 58 65 65 28 58 39 39 21 42 43 36 43 41 50 59 59 59 50 49 58 49 45 49 54 52 52 54 45 16 14 15 25 23 27 26 26 23 85 94 94 92 93 88 94 91 54 154 177 176 85 177 177 177 103 171 175 92 94 94 92 92 59 9...
result:
ok 290047 lines
Test #26:
score: 0
Accepted
time: 193ms
memory: 40508kb
input:
10000 10 10 1 1 2 4 3 4 3 1 1 8 9 5 8 2 8 2 10 1 1 1 8 5 7 9 8 6 5 7 7 10 10 1 2 3 2 5 1 3 4 2 3 1 2 10 2 6 2 6 10 2 9 5 6 3 4 3 8 8 6 1 9 9 1 1 3 3 5 2 3 1 8 1 2 3 6 4 5 8 4 3 1 5 1 4 2 5 8 6 10 10 1 1 1 4 4 3 5 6 6 7 2 5 2 8 10 4 4 8 1 10 2 4 7 9 3 3 7 1 9 10 10 1 1 3 3 3 2 5 7 9 8 8 1 2 10 8 7 7 ...
output:
126 135 130 126 120 125 90 126 135 45 134 127 129 129 127 137 135 116 58 131 91 92 88 87 85 92 91 94 88 100 114 113 105 114 117 114 118 67 116 26 69 90 45 75 87 65 78 62 78 83 29 73 84 29 37 73 83 70 74 75 77 74 73 26 76 74 33 38 35 40 40 26 49 48 86 78 102 101 96 30 87 75 84 100 62 64 23 57 46 73 6...
result:
ok 290027 lines
Test #27:
score: 0
Accepted
time: 184ms
memory: 33156kb
input:
10000 10 10 1 2 2 2 3 2 7 4 5 8 7 4 9 10 4 10 5 5 10 6 10 4 2 7 8 6 10 8 9 8 8 1 2 2 2 3 3 1 5 8 5 4 4 4 8 8 6 4 8 1 8 1 4 8 8 8 1 2 3 4 3 5 6 3 5 2 7 8 1 5 7 1 6 3 3 6 4 4 8 10 10 1 1 3 1 1 1 3 2 8 1 6 5 2 3 3 3 8 2 3 7 7 4 8 4 9 5 10 2 6 9 9 1 1 3 4 3 6 3 4 7 3 2 2 2 5 2 6 1 8 3 9 5 3 1 7 9 9 9 9 ...
output:
111 111 167 111 111 168 164 111 168 168 64 62 31 22 66 43 43 64 41 44 42 23 41 36 41 42 169 171 150 152 176 85 153 178 178 171 93 32 98 95 93 95 95 95 39 146 145 148 147 148 146 147 146 147 49 51 50 53 42 51 51 43 35 99 100 100 102 97 100 99 101 99 33 71 65 51 70 71 67 66 136 131 129 135 118 115 129...
result:
ok 290108 lines
Extra Test:
score: 0
Extra Test Passed