QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#67378 | #5098. 第一代图灵机 | myee | 0 | 1296ms | 88744kb | C++14 | 6.1kb | 2022-12-10 12:18:17 | 2022-12-10 12:19:31 |
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=10000;
typedef std::pair<llt,llt>Pair;
typedef std::pair<llt,Pair>Pair2;
typedef std::vector<Pair2>Lines;
const llt inf=1e18;
voi print(Lines Ls){
for(uint i=0;i<Ls.size();i++)
printf("%lld-%lld:y=%lldx+%lld\n",
Ls[i].first,i+1==Ls.size()?100ll:Ls[i+1].first,
Ls[i].second.first,Ls[i].second.second);
puts("---------------");
}
Lines Merge(Lines L1,Lines L2){
// print(L1);
// print(L2);
Lines R,Line;
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());
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]);
// print(Line);
return Line;
}
Lines get(llt s,llt h){
if(s<h)return{{0,{1,s}},{h-s,{0,h}}};
else return{{0,{0,h}}};
}
struct Seg{
Seg*L,*R;uint len,from;ullt H;
Lines Line;
voi buildLine(){
if(len==1)Line=get(A(from),H);
else{
std::vector<ullt>H={L->H};
for(uint r=from+(len>>1);r<from+len;r++)
H.push_back(std::min(H.back()+A(r),W(r)));
Line=L->Line;
for(uint i=1;i<H.size();i++)
Line=Merge(Line,get(S(from,from+(len>>1)+i),H[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),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-(len>>1)),
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
Time Limit Exceeded
Test #1:
score: 0
Time Limit Exceeded
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:
116965 88652 75931 92924 92924 92924 71480 95630 95630 95630 95630 88652 95630 95630 88652 116965 92924 91878 54390 116965 95630 95630 95630 39374 86171 116965 95603 95630 95630 93748 83104 95630 116965 95630 95630 95630 95630 95630 95630 26617 95630 95603 95630 116965 95630 95630 95603 95630 60731 ...
result:
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:
1174928 1101806 1174928 1174928 1174928 1174928 1174928 1174928 1174928 1174928 956246 1040942 1174928 1174928 1174928 1174928 1150452 1077217 1174928 1174928 1174928 1101806 1099756 1102884 1174928 1101806 1236670 1101806 1101806 1049432 862631 1236670 1236670 1049432 1101806 1236670 1101806 969969...
result:
Subtask #3:
score: 0
Wrong Answer
Test #5:
score: 0
Wrong Answer
time: 1296ms
memory: 88744kb
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:
46581050 46581050 38212888 38495755 38495755 42651674 38904210 46581050 46581050 46581050 27352881 38312006 46581050 46581050 42651674 42192087 38904210 42192087 46581050 46581050 46581050 41676405 46581050 34029095 46581050 38495755 46581050 28489436 46581050 42651674 42651674 37847969 46581050 465...
result:
wrong answer 1st lines differ - expected: '46702944', found: '46581050'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%