QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#205556 | #7565. Harumachi Kaze | ucup-team052# | TL | 0ms | 0kb | C++23 | 2.4kb | 2023-10-07 16:30:24 | 2023-10-07 16:30:25 |
answer
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define mod 998244353
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read()
{
char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
if(nega==-1) return -ans;
return ans;
}
void print(vector<int> x){for(int i=0;i<(int)x.size();i++) printf("%d%c",x[i]," \n"[i==(int)x.size()-1]);}
#define N 20005
int n,Q,B;
const int SIZ=125;
int Add(int x,int y)
{
#ifdef wasa855
return x+y;
#endif
printf("A %d %d\n",x,y); fflush(stdout);
return read();
}
int Cmp(int x,int y)
{
#ifdef wasa855
return x<y?x:y;
#endif
printf("C %d %d\n",x,y); fflush(stdout);
return read();
}
struct Arr
{
int a[N];
int bs[N],sum[N],pre[N];
int cnt;
void init()
{
cnt=0;
for(int i=0;i<n;i+=SIZ)
{
pre[i]=a[i];
sum[cnt]=pre[i];
for(int j=1;i+j<n&&j<SIZ;j++) pre[i+j]=Add(pre[i+j-1],a[i+j]),sum[cnt]=pre[i+j];
cnt++;
bs[cnt]=Add(bs[cnt-1],sum[cnt]);
}
}
int qry(int i)
{
if(i==n) return -1;
return Add(bs[i/SIZ],pre[i]);
}
void upd(int i,int v)
{
a[i]=v;
// printf("* %d %d\n",i,v);
int tw=i/SIZ;
pre[tw*SIZ]=a[tw*SIZ];
sum[tw]=pre[tw*SIZ];
for(int j=1;j<SIZ&&tw*SIZ+j<n;j++) pre[tw*SIZ+j]=Add(pre[tw*SIZ+j-1],a[tw*SIZ+j]),sum[tw]=pre[tw*SIZ+j];
for(int i=1;i<=cnt;i++) bs[i]=Add(bs[i-1],sum[i]);
}
}a,b;
int op[N],t[N],pos[N],x[N];
signed main()
{
cin>>n>>Q>>B;
for(int i=0;i<n;i++) a.a[i]=read();
for(int i=0;i<n;i++) b.a[i]=read();
for(int i=1;i<=Q;i++)
{
op[i]=read();
if(op[i]==1) t[i]=read(),pos[i]=read()-1,x[i]=read();
else t[i]=read();
}
a.init(),b.init();
vector<int> ANS;
for(int i=1;i<=Q;i++)
{
if(op[i]==1)
{
if(t[i]==1) a.upd(pos[i],x[i]);
else b.upd(pos[i],x[i]);
}
else
{
int l=0,r=min(n-1,t[i]-1),ans=n;
while(l<=r)
{
int mid=(l+r)/2;
int A=a.qry(mid),B=b.qry(t[i]-mid-2);
if(Cmp(A,B)==B) ans=mid,r=mid-1;
else l=mid+1;
}
if(ans==n) ANS.pb(b.qry(t[i]-n-1));
else
{
int A=a.qry(ans),B=b.qry(t[i]-ans-1);
ANS.pb(Cmp(A,B));
}
}
// for(int i=0;i<n;i++) printf("%d%c",b.qry(i)," \n"[i==n-1]);
}
printf("! %d\n",(int)ANS.size());
print(ANS);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
2 3 2 288230376151711744 864691128455135232 1441151880758558720 2017612633061982208 2 3 1 2 2 2594073385365405696 2 3 0 0 0 0 0 0 0 0
output:
A 0 0 A 0 0 A 0 0 A 0 0 A 0 0 A 0 0 C 0 0 A 0 0 C 0 -1