Submission #48326930


Source Code Expand

// LUOGU_RID: 138978857
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;

#define rep(i,l,r) for(int i(l);i<=(r);++i)
#define per(i,r,l) for(int i(r);i>=(l);--i)
#define eb emplace_back
#define File(filename) freopen(filename ".in","r",stdin),freopen(filename ".out","w",stdout)

#ifdef EXODUS
	#define Debug(...) fprintf(stderr,__VA_ARGS__)
#else
	#define Debug(...) 0
#endif

//=========================================================================================================
// Something about IO

template<typename T>
void read(T &x){
	x=0;T flg=1;
	char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')flg=-1;ch=getchar();}
	while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	x*=flg;
}
template<typename T,typename... Args>
void read(T &x,Args &...args){read(x),read(args...);}

//=========================================================================================================
// Define the global variables here.

bool membg=0;


constexpr int N=1e5+7;
ll n,q;
int m;
int a[N],b[N];

bool memed=0;

//=========================================================================================================
// Code here.

int getdep(ll l,ll r,ll p,int dep){
	// Debug("%lld %lld %lld\n",l,r,p);
	
	ll mid=(l*a[dep%m]+r*b[dep%m])/(a[dep%m]+b[dep%m]);
	if(mid==p)return dep;
	if(p<mid)return getdep(l,mid-1,p,dep+1);
	else return getdep(mid+1,r,p,dep+1);
}

ll calc(ll l,ll r,ll ql,ll qr,int dep){
	// Debug("%lld %lld %lld %lld\n",l,r,ql,qr);
	
	if(l>r||ql>r||qr<l)return 0ll;
	if(ql<=l&&r<=qr)return (r-l+1);
	
	ll mid=(l*a[dep%m]+r*b[dep%m])/(a[dep%m]+b[dep%m]);
	return calc(l,mid-1,ql,qr,dep+1)+calc(mid+1,r,ql,qr,dep+1)+1;
}

void solve(){
	read(n,m);
	for(int i=0;i<m;i++)read(a[i],b[i]);
	read(q);
	for(int i=1;i<=q;i++){
		ll l,r;
		read(l,r);
		ll ans=(calc(1,n,l,r,0)-1)*2-getdep(1,n,l,0)-getdep(1,n,r,0);
        printf("%lld\n",ans);
	}
	return;
}


//=========================================================================================================

int main(){
	Debug("%.3lfMB\n",fabs(&memed-&membg)/1024.0/1024.0);
	int timbg=clock();
	int T=1;
	while(T--)solve();
	int timed=clock();
	Debug("%.3lfs\n",1.0*(timed-timbg)/CLOCKS_PER_SEC);
	fflush(stdout);
	return 0;
}

Submission Info

Submission Time
Task E - Difference Sum Query
User EXODUS
Language C++ 17 (gcc 12.2)
Score 900
Code Size 2405 Byte
Status AC
Exec Time 32 ms
Memory 3864 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:18:28: warning: statement has no effect [-Wunused-value]
   18 |         #define Debug(...) 0
      |                            ^
Main.cpp:87:9: note: in expansion of macro ‘Debug’
   87 |         Debug("%.3lfMB\n",fabs(&memed-&membg)/1024.0/1024.0);
      |         ^~~~~
Main.cpp:18:28: warning: statement has no effect [-Wunused-value]
   18 |         #define Debug(...) 0
      |                            ^
Main.cpp:92:9: note: in expansion of macro ‘Debug’
   92 |         Debug("%.3lfs\n",1.0*(timed-timbg)/CLOCKS_PER_SEC);
      |         ^~~~~
Main.cpp:88:13: warning: unused variable ‘timbg’ [-Wunused-variable]
   88 |         int timbg=clock();
      |             ^~~~~
Main.cpp:91:13: warning: unused variable ‘timed’ [-Wunused-variable]
   91 |         int timed=clock();
      |             ^~~~~

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 1 ms 3744 KiB
00_sample_01.txt AC 1 ms 3720 KiB
01_srnd_00.txt AC 8 ms 3684 KiB
01_srnd_01.txt AC 8 ms 3688 KiB
01_srnd_02.txt AC 8 ms 3800 KiB
01_srnd_03.txt AC 8 ms 3684 KiB
01_srnd_04.txt AC 8 ms 3752 KiB
01_srnd_05.txt AC 8 ms 3748 KiB
01_srnd_06.txt AC 8 ms 3748 KiB
01_srnd_07.txt AC 8 ms 3744 KiB
01_srnd_08.txt AC 8 ms 3860 KiB
01_srnd_09.txt AC 8 ms 3748 KiB
02_rnd_00.txt AC 32 ms 3792 KiB
02_rnd_01.txt AC 30 ms 3680 KiB
02_rnd_02.txt AC 31 ms 3748 KiB
02_rnd_03.txt AC 31 ms 3864 KiB
02_rnd_04.txt AC 31 ms 3804 KiB
02_rnd_05.txt AC 29 ms 3736 KiB
02_rnd_06.txt AC 30 ms 3736 KiB
02_rnd_07.txt AC 29 ms 3680 KiB
02_rnd_08.txt AC 30 ms 3836 KiB
02_rnd_09.txt AC 30 ms 3860 KiB
03_worst_00.txt AC 21 ms 3808 KiB
03_worst_01.txt AC 10 ms 3748 KiB
03_worst_02.txt AC 10 ms 3736 KiB
03_worst_03.txt AC 18 ms 3808 KiB
03_worst_04.txt AC 21 ms 3736 KiB
03_worst_05.txt AC 10 ms 3688 KiB
03_worst_06.txt AC 10 ms 3716 KiB
03_worst_07.txt AC 18 ms 3688 KiB
04_max_00.txt AC 8 ms 3824 KiB
05_min_00.txt AC 1 ms 3688 KiB
06_root_00.txt AC 18 ms 3808 KiB
06_root_01.txt AC 18 ms 3804 KiB
06_root_02.txt AC 17 ms 3808 KiB
07_sall_00.txt AC 1 ms 3792 KiB
07_sall_01.txt AC 1 ms 3656 KiB
07_sall_02.txt AC 1 ms 3640 KiB
07_sall_03.txt AC 1 ms 3640 KiB
07_sall_04.txt AC 1 ms 3740 KiB
07_sall_05.txt AC 1 ms 3804 KiB
07_sall_06.txt AC 3 ms 3688 KiB
07_sall_07.txt AC 4 ms 3820 KiB
08_edge_00.txt AC 18 ms 3692 KiB
08_edge_01.txt AC 18 ms 3676 KiB
08_edge_02.txt AC 18 ms 3752 KiB
08_edge_03.txt AC 18 ms 3640 KiB
08_edge_04.txt AC 18 ms 3804 KiB