QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#76264 | #4253. Robot | lmeowdn | 40 | 928ms | 61144kb | C++14 | 3.5kb | 2023-02-08 18:31:50 | 2023-02-08 18:31:51 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define fi first
#define se second
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
typedef unsigned long long ull;
typedef __float128 ld;
int read() {
int x=0,w=1; char c=getchar();
while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
while(isdigit(c)) {x=x*10+c-'0'; c=getchar();}
return x*w;
}
const int N=6e5+9;
const ld eps=1e-5;
int n,m,a[N],t[N],mt,qt;
vi q,ans;
char c[N];
bool eq(ld a,ld b) {return b-eps<a&&a<b+eps;}
struct oper {int x,k;};
vector<oper> v[N];
struct node {
ld x,y;
node(ld _x=0,ld _y=0) {x=_x, y=_y;}
};
struct line {
ld k,b;
line(ld _k=0,ld _b=0) {k=_k, b=_b;}
line(ld _k,ld _x=0,ld _y=0) {k=_k, b=_y-_k*_x;}
line(node aa,node bb) {k=(aa.y-bb.y)/(aa.x-bb.x), b=aa.y-k*aa.x;}
ld f(ld x) {return k*x+b;}
};
struct polyline {
vector<node> p; int sz;
polyline() {p.clear(); sz=0;}
void push(node x) {p.eb(x), ++sz;}
void clear() {p.clear(); sz=0;}
vi query(vi t) {
vi ans(0); int pos=0; line cur(p[0],p[1]);
for(int x:t) {
while(pos<sz&&p[pos+1].x<x) pos++, cur=line(p[pos],p[pos+1]);
ld res=cur.f(x); ans.eb((int)(res+0.5));
}
return ans;
}
} s[N];
void get_add(ld x1,ld x2,ld l1,ld l2,ld r1,ld r2,polyline &res) {
if(l1<l2) swap(l1,l2), swap(r1,r2);
if(r1>=r2) res.push(node(x2,r1));
else {
ld x3=x1+(l1-l2)*(x2-x1)/(r2-r1+l1-l2);
ld y3=line(node(x1,l1),node(x2,r1)).f(x3);
res.push(node(x3,y3));
res.push(node(x2,r2));
}
}
polyline operator + (polyline a,polyline b) {
int pa=1, pb=1, sa=a.sz, sb=b.sz;
polyline res; res.push(node(0,max(a.p[0].y,b.p[0].y)));
ld lst=0, lsta=a.p[0].y, lstb=b.p[0].y;
rep(i,3,sa+sb) {
if(pa<sa&&eq(a.p[pa].x,lst)) pa++;
else if(pb<sb&&eq(b.p[pb].x,lst)) pb++;
else {
ld cur=min(a.p[pa].x,b.p[pb].x);
ld cura=line(a.p[pa-1],a.p[pa]).f(cur);
ld curb=line(b.p[pb-1],b.p[pb]).f(cur);
get_add(lst,cur,lsta,lstb,cura,curb,res);
lst=cur, lsta=cura, lstb=curb;
if(a.p[pa].x<b.p[pb].x) pa++;
else pb++;
}
}
return res;
}
polyline solve(int l,int r) {
if(l==r) return s[l]; int mid=l+r>>1;
return solve(l,mid)+solve(mid+1,r);
}
void work() {
rep(i,1,n) {
s[i].clear();
s[i].push(node(0,a[i]));
int sz=v[i].size(); line cur; cur.k=0, cur.b=a[i];
rep(j,0,sz-1) {
node cn(v[i][j].x,cur.f(v[i][j].x));
s[i].push(cn);
cur=line(v[i][j].k,cn.x,cn.y);
}
}
polyline rp=solve(1,n);
vi res=rp.query(q);
rep(i,0,qt-1) ans[i]=max(ans[i],res[i]);
}
signed main() {
n=read(), m=read();
rep(i,1,n) a[i]=read();
rep(i,1,m) {
scanf("%lld%s",&t[i],c);
if(c[0]=='q') q.eb(t[i]), qt++;
else {
int k=read(), x=read();
v[k].eb((oper){t[i],x});
}
mt=max(mt,t[i]);
}
rep(i,1,n) v[i].eb((oper){mt,0});
ans.resize(q.size());
work();
rep(i,1,n) a[i]=-a[i];
rep(i,1,n) for(oper &p:v[i]) p.k=-p.k;
work();
rep(i,0,qt-1) printf("%lld\n",ans[i]);
return 0;
}
詳細信息
Test #1:
score: 10
Accepted
time: 36ms
memory: 39768kb
input:
1999 2000 199 8854 -9513 9848 8434 -6615 -6770 4057 -9730 686 1586 6806 -511 -6328 -2250 2785 -4083 -3961 -711 9606 -9391 1041 -2844 -4889 993 -6955 -1982 -5300 9053 -5275 3950 -7977 -3652 8624 -716 -2013 -5229 -3686 -4602 -5031 9777 3802 491 -1354 -26 -3366 5285 5805 -7098 2233 -5967 -1318 -4553 63...
output:
86968438 360434523 838136414 913544563 969488608 1039885818 1109817781 1176515896 1251176599 1310476524 1510654766 1541254290 1558186230 1650869534 1683894444 1758250067 1785951331 1924000031 1993298953 2050165865 2254081337 2698178666 2750011758 2975976887 3216807039 3276625600 3332455240 335270492...
result:
ok 980 numbers
Test #2:
score: 10
Accepted
time: 34ms
memory: 40220kb
input:
1999 2000 6817 4353 -8180 954 -2553 1768 4986 -889 7032 -450 1234 -7637 9636 380 3607 -2296 -4881 -9025 2375 -1561 -8807 -3103 4385 8883 -2887 -1185 1960 6711 3478 -1056 -1717 -534 -9885 -6301 6011 5965 -9833 -5181 5329 3688 -6837 9023 64 -8326 3021 -7193 -9218 -4699 2354 -4720 1621 7361 -5233 9211 ...
output:
9999 6877566 19288910 55025322 173050121 235131941 259226075 297353495 487371773 672366281 768849281 844199177 852243863 1019578655 1077348683 1147535075 1160789843 1226398283 1261072277 1340915371 1413759421 1576022921 1664672671 1707990671 1778999971 1838562221 1977886871 2055492321 2318326971 235...
result:
ok 994 numbers
Test #3:
score: 0
Time Limit Exceeded
input:
99659 99039 -39276177 -64464963 -70081363 -443045475 -655771408 -409419920 -285052520 -312069074 -936205590 -10621715 -908116392 -660740279 -953732094 -591542519 -194540162 -139991296 -705911340 -778931920 -474438963 -518208970 -59960466 -981034014 -514533441 -217486555 -711871023 -615144144 -631291...
output:
result:
Test #4:
score: 0
Time Limit Exceeded
input:
99572 579859 -100705410 -669206879 -432488010 -384767624 -742351351 -839681487 -968882737 -976751481 57117493 -959321678 -819420190 -325014480 -636525861 -382469947 -876672604 -213012287 -209210199 -875230847 -920443172 -731589320 -946964322 -789362448 -872075805 -828546101 51836817 -913319025 -8404...
output:
result:
Test #5:
score: 0
Time Limit Exceeded
input:
99320 577219 -525813544 -959369807 -718451747 -533082399 -787662356 -531754846 -650759294 -381852570 -979346470 -644489626 -425559804 -332888497 -203462089 -292970440 -958637976 -533593640 53499163 -331134986 -296264838 -806780896 -651958364 -547743072 -590243769 -75974484 -843772303 -367318307 -443...
output:
result:
Test #6:
score: 10
Accepted
time: 928ms
memory: 59520kb
input:
90498 99230 -33558917 30715649 81001133 -12438113 81315374 -70949846 -71212693 66569129 -16194103 -63049353 -79869090 97189792 61301532 53180861 -26423528 -30279746 32502058 7951680 -97121356 -5044511 -4113729 82719257 96311627 80260870 -29075735 -31473462 -27928703 81572824 -89715849 85470402 -5284...
output:
106294952 110163416 118535792 121674188 127268720 127704968 131859284 137162984 139716728 142361108 151520324 153761324 159719396 164628680 167492180 175844636 185014808 186302636 187034696 195742724 204533420 207048320 213505388 220715432 226279088 230415476 231647528 234046892 240457148 243998924 ...
result:
ok 50858 numbers
Test #7:
score: 10
Accepted
time: 914ms
memory: 61144kb
input:
99124 99428 -29121705 73122072 14759978 -93785828 -52964748 50664810 -67789167 38732351 -57330970 48764999 -73647685 92261655 2267455 -21312555 -51092994 33675829 40607569 -85559394 -93024695 24124094 -45466947 -66665193 -99870070 -58435829 -56724651 -98854388 86610996 59912463 -27223092 85984568 94...
output:
106340510 113640698 116739890 122754640 124220766 127865950 128706392 135771234 142501746 142918910 150583550 157918850 162749170 171812008 180577442 182247096 185391794 194654232 201310892 209518444 210866742 213027412 213683098 222590248 225580256 231447498 239671018 249411498 250792730 251150014 ...
result:
ok 57640 numbers
Test #8:
score: 0
Time Limit Exceeded
input:
99538 99031 -501609067 -774687736 -928215759 -477038092 -823455674 -871460165 -852927043 -704708804 -775793387 -521621627 -923721630 -811686668 -952989802 -841891941 -482572032 -509003031 -595485934 -831251065 -616219801 -580804479 -951849211 -783134298 -505096225 -625789647 -520043618 -798430551 -6...
output:
result:
Test #9:
score: 0
Time Limit Exceeded
input:
99483 590517 -508842 -191922 830365 -321837 163127 -225035 -3981 -222030 721775 -244372 -342954 -692168 -156349 -853744 -606213 687012 -401837 -920227 -198596 -14000 -345069 -628969 -386394 -590462 97339 -974255 -551821 -623120 -673402 -567398 278012 511781 29418 -975780 -416796 902045 -565858 -2455...
output:
result:
Test #10:
score: 0
Time Limit Exceeded
input:
99801 597343 -32417 984702 259080 747296 807167 169192 454040 -426594 582296 321692 800273 962596 -968901 42596 -304443 574664 936854 271860 902411 38804 -688175 55613 31189 -930407 -544084 -164683 -442201 118338 -858190 -109300 682685 896380 -887043 357053 -908865 890420 -680972 632527 -106741 -668...