Submission #1777586
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int m,n,Q;
struct func{
int a,b,w,t,k;
int g(int x){
if(x<=a)return w;
if(x<=b)return w+x-a;
return w+b-a;
}
void expand(int dt){
t+=dt;w+=dt*k;k=-k;
if(w+b-a<=0)a=b=m,w=0;else if(w<0)a-=w,w=0;
if(w>=m)a=b=m,w=m;else if(w+b-a>m)b-=w+b-a-m;
}
}f[N];
bool operator<(const int&a,const func&b){return a<b.t;}
int main(){
scanf("%d%d",&m,&n);
f[0]=(func){0,m,0,0,-1};
for(int i=1,t;i<=n;i++)f[i]=f[i-1],scanf("%d",&t),f[i].expand(t-f[i].t);
scanf("%d",&Q);
for(int t,a,p,r;Q--;){
scanf("%d%d",&t,&a);
p=upper_bound(f,f+n+1,t)-f-1;
r=f[p].g(a)+(t-f[p].t)*f[p].k;
if(r<0)r=0;if(r>m)r=m;
printf("%d\n",r);
}
return 0;
}
Submission Info
Submission Time |
|
Task |
F - Sandglass |
User |
whzzt |
Language |
C++14 (GCC 5.4.1) |
Score |
700 |
Code Size |
749 Byte |
Status |
AC |
Exec Time |
50 ms |
Memory |
3200 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:24:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&m,&n);
^
./Main.cpp:26:73: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
for(int i=1,t;i<=n;i++)f[i]=f[i-1],scanf("%d",&t),f[i].expand(t-f[i].t);
^
./Main.cpp:27:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&Q);
^
./Main.cpp:29:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&t,&a);
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
700 / 700 |
Status |
|
|
Set Name |
Test Cases |
Sample |
0_000.txt, 0_001.txt, 0_002.txt |
All |
0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt, 1_026.txt, 1_027.txt, 1_028.txt, 1_029.txt, 1_030.txt, 1_031.txt, 1_032.txt, 1_033.txt, 1_034.txt, 1_035.txt, 1_036.txt, 1_037.txt, 1_038.txt, 1_039.txt, 1_040.txt, 1_041.txt |
Case Name |
Status |
Exec Time |
Memory |
0_000.txt |
AC |
1 ms |
256 KB |
0_001.txt |
AC |
1 ms |
256 KB |
0_002.txt |
AC |
1 ms |
256 KB |
1_003.txt |
AC |
41 ms |
2432 KB |
1_004.txt |
AC |
42 ms |
2432 KB |
1_005.txt |
AC |
44 ms |
2432 KB |
1_006.txt |
AC |
40 ms |
2432 KB |
1_007.txt |
AC |
42 ms |
2432 KB |
1_008.txt |
AC |
44 ms |
2432 KB |
1_009.txt |
AC |
41 ms |
2432 KB |
1_010.txt |
AC |
42 ms |
2432 KB |
1_011.txt |
AC |
44 ms |
2432 KB |
1_012.txt |
AC |
41 ms |
2560 KB |
1_013.txt |
AC |
42 ms |
2560 KB |
1_014.txt |
AC |
45 ms |
2560 KB |
1_015.txt |
AC |
42 ms |
2688 KB |
1_016.txt |
AC |
43 ms |
2688 KB |
1_017.txt |
AC |
46 ms |
2688 KB |
1_018.txt |
AC |
44 ms |
2816 KB |
1_019.txt |
AC |
45 ms |
2816 KB |
1_020.txt |
AC |
46 ms |
2816 KB |
1_021.txt |
AC |
44 ms |
2688 KB |
1_022.txt |
AC |
45 ms |
2816 KB |
1_023.txt |
AC |
47 ms |
2816 KB |
1_024.txt |
AC |
44 ms |
2688 KB |
1_025.txt |
AC |
46 ms |
2944 KB |
1_026.txt |
AC |
48 ms |
2944 KB |
1_027.txt |
AC |
45 ms |
2688 KB |
1_028.txt |
AC |
47 ms |
2816 KB |
1_029.txt |
AC |
49 ms |
3072 KB |
1_030.txt |
AC |
46 ms |
2816 KB |
1_031.txt |
AC |
47 ms |
2816 KB |
1_032.txt |
AC |
50 ms |
3200 KB |
1_033.txt |
AC |
31 ms |
1024 KB |
1_034.txt |
AC |
33 ms |
1024 KB |
1_035.txt |
AC |
46 ms |
2944 KB |
1_036.txt |
AC |
33 ms |
1152 KB |
1_037.txt |
AC |
34 ms |
1152 KB |
1_038.txt |
AC |
48 ms |
3072 KB |
1_039.txt |
AC |
33 ms |
896 KB |
1_040.txt |
AC |
35 ms |
1280 KB |
1_041.txt |
AC |
50 ms |
3200 KB |