QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#67312 | #5098. 第一代图灵机 | myee | 0 | 1604ms | 91248kb | C++14 | 5.8kb | 2022-12-10 11:43:30 | 2022-12-10 11:43:32 |
Judging History
answer
// 那就是希望。
// 即便需要取模,也是光明。
// 线段树大科技题。
// 自己 yy 出来一个奇葩做法,使得构成一个可以维护的非半群信息。
// 但是修改代价太大了。
// 考虑怎么办。
// 考虑嗯做。
// 直接,直接扔一个底层分块上去啊!
// 很快啊!
// 希望能暴力草过。
// bruteforce!
// 我感觉我很有精神!
// 写得我直接 /tuu 了
#include <algorithm>
#include <set>
#include <stdio.h>
#include <vector>
typedef long long llt;
typedef unsigned uint;typedef unsigned long long ullt;
typedef bool bol;typedef char chr;typedef void voi;
typedef double dbl;
template<typename T>bol _max(T&a,T b){return(a<b)?a=b,true:false;}
template<typename T>bol _min(T&a,T b){return(b<a)?a=b,true:false;}
template<typename T>T lowbit(T n){return n&-n;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T lcm(T a,T b){return(a!=0||b!=0)?a/gcd(a,b)*b:(T)0;}
template<typename T>T exgcd(T a,T b,T&x,T&y){if(b!=0){T ans=exgcd(b,a%b,y,x);y-=a/b*x;return ans;}else return y=0,x=1,a;}
template<typename T>T power(T base,T index,T mod)
{
T ans=1%mod;
while(index)
{
if(index&1)ans=ans*base%mod;
base=base*base%mod,index>>=1;
}
return ans;
}
ullt V[200005];uint Pre[200005];
ullt S(uint l,uint r){return V[r]-V[l];}
ullt A(uint p){return S(p,p+1);}
ullt T(uint l,uint r){return S(Pre[r],l+1);}
ullt W(uint l){return T(l,l+1);}
struct Info{ullt F,G,H;};
const uint B=500;
typedef std::pair<llt,llt>Pair;
typedef std::pair<llt,Pair>Pair2;
const llt inf=1e18;
struct Seg{
Seg*L,*R;uint len,from;ullt H;
std::vector<Pair2>Line;
voi buildLine(){ // 不凸的凸壳暴力合并。
Line.clear();
if(len==1)Line={{0,{1,A(from)}},{W(from)-A(from),{0,W(from)}}};
else{
auto L1=L->Line,L2=R->Line;
uint d=std::min(L->H,S(from,from+(len>>1)));
for(auto&s:L2)s.first-=d,s.second.second+=s.second.first*d;
uint p=0;while(p+1<L2.size()&&L2[p+1].first<=0)p++;
L2.erase(L2.begin(),L2.begin()+p),L2[0].first=0;
std::vector<llt>X,User1,User2;
for(auto s:L1)User1.push_back(s.first);
for(auto s:L2)User2.push_back(s.first);
X.resize(User1.size()+User2.size());
std::merge(User1.begin(),User1.end(),User2.begin(),User2.end(),X.begin());
X.erase(std::unique(X.begin(),X.end()),X.end());
std::vector<Pair2>R;
for(uint i=0,j=0;i<X.size();i++){
while(j+1<L1.size()&&L1[j+1].first<=X[i])j++;
R.push_back({X[i],L1[j].second});
}
L1=R;R.clear();
for(uint i=0,j=0;i<X.size();i++){
while(j+1<L2.size()&&L2[j+1].first<=X[i])j++;
R.push_back({X[i],L2[j].second});
}
L2=R;R.clear();
for(uint i=0;i<X.size();i++)
{
Pair l1=L1[i].second,l2=L2[i].second;
if(l1.first==l2.first)R.push_back({X[i],std::max(l1,l2)});
else{
if(l1>l2)std::swap(l1,l2);
llt p=l1.second-l2.second;
if(p<=X[i])R.push_back({X[i],l2});
else if(i+1<X.size()&&X[i+1]>=p)R.push_back({X[i],l1});
else R.push_back({X[i],l1}),R.push_back({p,l2});
}
}
for(uint i=0;i<R.size();i++)if(!i||R[i].second!=R[i-1].second)Line.push_back(R[i]);
}
}
Seg(uint l,uint r):L(NULL),R(NULL),len(r-l),from(l){
if(len>1)
L=new Seg(l,(l+r)>>1),R=new Seg((l+r)>>1,r),
H=std::min(L->H+S((l+r)>>1,r),R->H);
else H=W(l);
if(len<=B)buildLine();
}
Info query(uint l,uint r,ullt v){
if(!l&&r==len&&len<=B){
auto p=std::upper_bound(Line.begin(),Line.end(),Pair2{v,{inf,inf}})[-1].second;
return{std::min(S(from,from+len)+v,H),p.first*v+p.second,H};
}
if(l<(len>>1))
if(r<=(len>>1))return L->query(l,r,v);
else{
Info t1=L->query(l,len>>1,v);
Info t2=R->query(0,r-(len>>1),v+t1.F);
return{std::min({v+S(from+l,from+r),t1.H+S(from+(len>>1),from+r),t2.H}),
std::max(t1.G,t2.G),std::min(t1.H+S(from+(len>>1),from+r),t2.H)};
}
else return R->query(l-(len>>1),r-(len>>1),v);
}
voi update(uint p){
if(len==1)H=W(from);
else
p<(len>>1)?L->update(p):R->update(p),
H=std::min(L->H+S(from+(len>>1),from+len),R->H);
if(len<=B)buildLine();
}
};
std::set<uint>Set[200005];
uint C[200005];
int main()
{
#ifdef MYEE
freopen("QAQ.in","r",stdin);
// freopen("QAQ.out","w",stdout);
#else
#if !defined(ONLINE_JUDGE)
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
#endif
uint n,m,q;scanf("%u%u%u",&n,&m,&q);
for(uint i=0;i<n;i++)scanf("%llu",V+i+1),V[i+1]+=V[i];
for(uint i=0;i<m;i++)Set[i].insert(0);
for(uint i=0;i<n;i++)scanf("%u",C+i),Pre[i]=*--Set[--C[i]].insert(i+1).first;
Seg S(0,n);
while(q--){
uint op;scanf("%u",&op);
if(op==1){
uint l,r;scanf("%u%u",&l,&r);
printf("%llu\n",S.query(l-1,r,0).G);
}else{
uint p;scanf("%u",&p),p--;
Set[C[p]].erase(p+1);
auto t=Set[C[p]].upper_bound(p);
if(t!=Set[C[p]].end())Pre[*t]=Pre[p],S.update(*t);
scanf("%u",C+p);
t=Set[--C[p]].insert(p+1).first;
if(++t!=Set[C[p]].end())Pre[*t]=p,S.update(*t);
--t;Pre[p]=*--t;S.update(p);
}
}
return 0;
}
// 那就是希望。
// 即便需要取模,也是光明。
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 35ms
memory: 17396kb
input:
5000 200 5000 2315 3433 1793 4621 4627 4561 289 4399 3822 2392 392 4581 2643 2441 4572 4649 2981 3094 4206 2057 761 2516 2849 3509 3033 658 4965 3316 3269 4284 4961 753 1187 2515 1377 1725 4743 4761 3823 3464 4859 989 2401 953 875 1481 2181 103 2067 2625 3296 4721 61 3843 1607 997 4385 1284 4299 441...
output:
548314 245673 235275 308423 225966 210806 259594 235530 251425 251425 225966 245673 557600 254636 172427 469715 174076 279177 87601 308423 254636 334710 268088 60775 205859 350545 334103 226905 213296 208193 204744 226905 350545 268088 440399 213296 350545 226905 268088 28995 907253 251425 268088 30...
result:
wrong answer 1st lines differ - expected: '118571', found: '548314'
Subtask #2:
score: 0
Time Limit Exceeded
Test #3:
score: 0
Time Limit Exceeded
input:
200000 10 200000 55651 97298 108697 86619 60721 199951 10610 162267 154301 138848 39191 18605 101369 57073 34977 101576 71252 143401 89587 160521 166491 38442 150761 35579 25571 121311 38033 38483 144639 41401 179161 54872 157905 137601 46863 187656 171901 43715 41036 150741 69057 102031 130561 4772...
output:
4207783 3288581 3727229 3727229 4207783 4207783 4207783 4207783 3727229 4207783 2301159 2785890 4207783 4207783 4207783 4207783 3790607 3247466 4207783 4207783 4207783 3288581 3854408 3666122 3332587 3288581 4207783 3437452 3933021 3174750 2734201 4207783 4207783 3933021 3933021 4207783 3362840 1912...
result:
Subtask #3:
score: 0
Wrong Answer
Test #5:
score: 0
Wrong Answer
time: 1604ms
memory: 91248kb
input:
200000 20000 200000 30681 32496 35471 48191 159123 69792 120915 150673 187226 158493 36275 26856 107976 124777 145229 69745 183961 14497 144808 153612 185893 137681 66417 46802 19345 113322 168046 128149 191001 135433 13201 139214 59489 81178 42343 163158 110121 119201 97501 53079 158755 192241 1132...
output:
499989467 173199150 155538369 510612235 400319187 173199150 135823673 173199150 626455513 153483111 683664191 159023009 680408508 173199150 165580949 414063767 317595410 329297616 173199150 177464227 506346095 143317826 193264455 148920329 173199150 510285576 173199150 73819605 173199150 165580949 2...
result:
wrong answer 1st lines differ - expected: '46702944', found: '499989467'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%