提出 #52241239


ソースコード 拡げる

// LUOGU_RID: 155323492
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m,q,a[105],b[105];
ll dep(ll x,ll l,ll r,ll i) {
	ll mid=(l*a[i%m]+r*b[i%m])/(a[i%m]+b[i%m]);
	if(x<mid) return dep(x,l,mid-1,i+1);
	if(mid<x) return dep(x,mid+1,r,i+1);
	return i;
}
ll cnt(ll ql,ll qr,ll l,ll r,ll i) {
	if(ql<=l&&r<=qr) return r-l+1;
	ll mid=(l*a[i%m]+r*b[i%m])/(a[i%m]+b[i%m]),ans=1;
	if(ql<mid) ans+=cnt(ql,qr,l,mid-1,i+1);
	if(mid<qr) ans+=cnt(ql,qr,mid+1,r,i+1);
	return ans;
}
signed main() {
	scanf("%lld%lld",&n,&m);
	for(int i=0;i<m;++i) scanf("%lld%lld",&a[i],&b[i]);
	scanf("%lld",&q);
	for(ll l,r;q--;) {
		scanf("%lld%lld",&l,&r);
		printf("%lld\n",2*(cnt(l,r,1,n,0)-1)-dep(l,1,n,0)-dep(r,1,n,0));
	}
	return 0;
}

提出情報

提出日時
問題 E - Difference Sum Query
ユーザ DaiRuiChen007
言語 C++ 17 (gcc 12.2)
得点 900
コード長 766 Byte
結果 AC
実行時間 35 ms
メモリ 3920 KiB

コンパイルエラー

Main.cpp: In function ‘int main()’:
Main.cpp:20:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 |         scanf("%lld%lld",&n,&m);
      |         ~~~~~^~~~~~~~~~~~~~~~~~
Main.cpp:21:35: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   21 |         for(int i=0;i<m;++i) scanf("%lld%lld",&a[i],&b[i]);
      |                              ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:22:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   22 |         scanf("%lld",&q);
      |         ~~~~~^~~~~~~~~~~
Main.cpp:24:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   24 |                 scanf("%lld%lld",&l,&r);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 900 / 900
結果
AC × 2
AC × 48
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3784 KiB
00_sample_01.txt AC 1 ms 3784 KiB
01_srnd_00.txt AC 10 ms 3688 KiB
01_srnd_01.txt AC 11 ms 3660 KiB
01_srnd_02.txt AC 10 ms 3576 KiB
01_srnd_03.txt AC 10 ms 3800 KiB
01_srnd_04.txt AC 10 ms 3528 KiB
01_srnd_05.txt AC 10 ms 3580 KiB
01_srnd_06.txt AC 10 ms 3784 KiB
01_srnd_07.txt AC 10 ms 3704 KiB
01_srnd_08.txt AC 10 ms 3916 KiB
01_srnd_09.txt AC 10 ms 3784 KiB
02_rnd_00.txt AC 35 ms 3804 KiB
02_rnd_01.txt AC 33 ms 3664 KiB
02_rnd_02.txt AC 34 ms 3672 KiB
02_rnd_03.txt AC 33 ms 3720 KiB
02_rnd_04.txt AC 34 ms 3668 KiB
02_rnd_05.txt AC 32 ms 3668 KiB
02_rnd_06.txt AC 33 ms 3704 KiB
02_rnd_07.txt AC 32 ms 3660 KiB
02_rnd_08.txt AC 33 ms 3784 KiB
02_rnd_09.txt AC 34 ms 3852 KiB
03_worst_00.txt AC 23 ms 3900 KiB
03_worst_01.txt AC 10 ms 3772 KiB
03_worst_02.txt AC 11 ms 3660 KiB
03_worst_03.txt AC 18 ms 3788 KiB
03_worst_04.txt AC 23 ms 3688 KiB
03_worst_05.txt AC 10 ms 3576 KiB
03_worst_06.txt AC 11 ms 3660 KiB
03_worst_07.txt AC 18 ms 3920 KiB
04_max_00.txt AC 9 ms 3700 KiB
05_min_00.txt AC 1 ms 3912 KiB
06_root_00.txt AC 20 ms 3912 KiB
06_root_01.txt AC 20 ms 3576 KiB
06_root_02.txt AC 19 ms 3580 KiB
07_sall_00.txt AC 1 ms 3784 KiB
07_sall_01.txt AC 1 ms 3656 KiB
07_sall_02.txt AC 1 ms 3660 KiB
07_sall_03.txt AC 1 ms 3664 KiB
07_sall_04.txt AC 1 ms 3660 KiB
07_sall_05.txt AC 1 ms 3720 KiB
07_sall_06.txt AC 4 ms 3660 KiB
07_sall_07.txt AC 4 ms 3776 KiB
08_edge_00.txt AC 19 ms 3656 KiB
08_edge_01.txt AC 19 ms 3660 KiB
08_edge_02.txt AC 19 ms 3664 KiB
08_edge_03.txt AC 19 ms 3704 KiB
08_edge_04.txt AC 19 ms 3916 KiB