Submission #42213921


Source Code Expand

#include<cstdio>
#include<cstring>
#define N 110
#define fep(i,x,y) for(int i=x;i<=y;i++)
#define feq(i,x,y) for(int i=x;i>=y;i--)
using namespace std;
typedef long long LL;
LL a[N],b[N];
int n,Q;LL nn;
LL sol(LL l,LL r,LL id,LL &cnt,LL ll,LL rr,LL t){
	LL ans=0;
	while(1){
		LL tt=t%n;
		LL mid=(a[tt]*l+b[tt]*r)/(a[tt]+b[tt]);
		if(mid<ll || mid>rr)cnt++;
		if(mid==id)return ans;
		else if(mid<id)l=mid+1;
		else r=mid-1;
		t++;ans++;
	}
}
LL solve(LL ll,LL rr){
	LL l=1,r=nn,t=0;
	while(1){
		LL tt=t%n;
		LL mid=(a[tt]*l+b[tt]*r)/(a[tt]+b[tt]);
		if(ll<=mid && mid<=rr){
			break;
		}
		else if(mid<ll)l=mid+1;
		else r=mid-1;
		t++;
	}
	LL cnt=rr-ll+1;
	LL ans=sol(l,r,ll,cnt,ll,rr,t)+sol(l,r,rr,cnt,ll,rr,t);
	return (cnt-1)*2-ans;
}
int main(){
	scanf("%lld%d",&nn,&n);
	fep(i,0,n-1)scanf("%lld%lld",&a[i],&b[i]);
	scanf("%d",&Q);
	fep(i,1,Q){
		LL l,r;scanf("%lld%lld",&l,&r);
		printf("%lld\n",solve(l,r));
	}
	return 0;
}

Submission Info

Submission Time
Task E - Difference Sum Query
User juruozjj
Language C++ (GCC 9.2.1)
Score 900
Code Size 979 Byte
Status AC
Exec Time 39 ms
Memory 1664 KiB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:39:7: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   39 |  scanf("%lld%d",&nn,&n);
      |  ~~~~~^~~~~~~~~~~~~~~~~
./Main.cpp:40:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   40 |  fep(i,0,n-1)scanf("%lld%lld",&a[i],&b[i]);
      |              ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
./Main.cpp:41:7: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   41 |  scanf("%d",&Q);
      |  ~~~~~^~~~~~~~~
./Main.cpp:43:15: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   43 |   LL l,r;scanf("%lld%lld",&l,&r);
      |          ~~~~~^~~~~~~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 900 / 900
Status
AC × 2
AC × 48
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_srnd_00.txt, 01_srnd_01.txt, 01_srnd_02.txt, 01_srnd_03.txt, 01_srnd_04.txt, 01_srnd_05.txt, 01_srnd_06.txt, 01_srnd_07.txt, 01_srnd_08.txt, 01_srnd_09.txt, 02_rnd_00.txt, 02_rnd_01.txt, 02_rnd_02.txt, 02_rnd_03.txt, 02_rnd_04.txt, 02_rnd_05.txt, 02_rnd_06.txt, 02_rnd_07.txt, 02_rnd_08.txt, 02_rnd_09.txt, 03_worst_00.txt, 03_worst_01.txt, 03_worst_02.txt, 03_worst_03.txt, 03_worst_04.txt, 03_worst_05.txt, 03_worst_06.txt, 03_worst_07.txt, 04_max_00.txt, 05_min_00.txt, 06_root_00.txt, 06_root_01.txt, 06_root_02.txt, 07_sall_00.txt, 07_sall_01.txt, 07_sall_02.txt, 07_sall_03.txt, 07_sall_04.txt, 07_sall_05.txt, 07_sall_06.txt, 07_sall_07.txt, 08_edge_00.txt, 08_edge_01.txt, 08_edge_02.txt, 08_edge_03.txt, 08_edge_04.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 4 ms 1576 KiB
00_sample_01.txt AC 1 ms 1612 KiB
01_srnd_00.txt AC 18 ms 1584 KiB
01_srnd_01.txt AC 14 ms 1560 KiB
01_srnd_02.txt AC 13 ms 1652 KiB
01_srnd_03.txt AC 15 ms 1604 KiB
01_srnd_04.txt AC 14 ms 1572 KiB
01_srnd_05.txt AC 23 ms 1604 KiB
01_srnd_06.txt AC 16 ms 1600 KiB
01_srnd_07.txt AC 14 ms 1584 KiB
01_srnd_08.txt AC 14 ms 1600 KiB
01_srnd_09.txt AC 15 ms 1568 KiB
02_rnd_00.txt AC 37 ms 1568 KiB
02_rnd_01.txt AC 38 ms 1656 KiB
02_rnd_02.txt AC 38 ms 1644 KiB
02_rnd_03.txt AC 39 ms 1592 KiB
02_rnd_04.txt AC 37 ms 1588 KiB
02_rnd_05.txt AC 34 ms 1596 KiB
02_rnd_06.txt AC 38 ms 1620 KiB
02_rnd_07.txt AC 37 ms 1600 KiB
02_rnd_08.txt AC 38 ms 1568 KiB
02_rnd_09.txt AC 38 ms 1584 KiB
03_worst_00.txt AC 32 ms 1664 KiB
03_worst_01.txt AC 18 ms 1588 KiB
03_worst_02.txt AC 16 ms 1608 KiB
03_worst_03.txt AC 27 ms 1656 KiB
03_worst_04.txt AC 26 ms 1612 KiB
03_worst_05.txt AC 18 ms 1616 KiB
03_worst_06.txt AC 17 ms 1576 KiB
03_worst_07.txt AC 28 ms 1608 KiB
04_max_00.txt AC 34 ms 1588 KiB
05_min_00.txt AC 3 ms 1656 KiB
06_root_00.txt AC 29 ms 1616 KiB
06_root_01.txt AC 28 ms 1656 KiB
06_root_02.txt AC 23 ms 1588 KiB
07_sall_00.txt AC 1 ms 1576 KiB
07_sall_01.txt AC 3 ms 1656 KiB
07_sall_02.txt AC 2 ms 1584 KiB
07_sall_03.txt AC 1 ms 1576 KiB
07_sall_04.txt AC 1 ms 1580 KiB
07_sall_05.txt AC 2 ms 1600 KiB
07_sall_06.txt AC 11 ms 1656 KiB
07_sall_07.txt AC 10 ms 1588 KiB
08_edge_00.txt AC 30 ms 1664 KiB
08_edge_01.txt AC 26 ms 1648 KiB
08_edge_02.txt AC 33 ms 1580 KiB
08_edge_03.txt AC 30 ms 1648 KiB
08_edge_04.txt AC 30 ms 1580 KiB