Submission #56309048


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,m,q,h[200002][2];
vector<pair<int,int>> g[200002];
map<int,map<int,int>> mp;
signed main()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int t,p;
		scanf("%lld%lld",&t,&p);
		if(h[p][0]==0) h[p][0]=1,h[p][1]=t;
		else h[p][0]=0,g[p].push_back({t,h[p][1]});
	}
	for(int i=1;i<=n;i++) sort(g[i].begin(),g[i].end());
	//for(int i=1;i<=n;i++)
	//{
	//	cout<<i<<"\n";
	//	for(int j=0;j<g[i].size();j++) cout<<g[i][j].first<<" "<<g[i][j].second<<"\n";
	//}
	cin>>q;
	for(int i=1;i<=q;i++)
	{
		int l,r,sum=0;
		scanf("%lld%lld",&l,&r);
		if(mp[l][r])
		{
			printf("%lld\n",mp[l][r]);
			continue;
		}
		for(int j=0;j<g[r].size();j++)
			for(int k=g[l].size()-1;k>=0;k--)
			{
				int l1=g[l][k].second,r1=g[l][k].first,l2=g[r][j].second,r2=g[r][j].first;
				//cout<<l1<<" "<<r1<<" "<<l2<<" "<<r2<<"\n";
				if(max(l1,l2)<=min(r1,r2)) sum+=min(r1,r2)-max(l1,l2);
				else if(r1<l2) break;
			}
		mp[l][r]=sum;
		printf("%lld\n",mp[l][r]);
	}
	return 0;
}

Submission Info

Submission Time
Task G - AtCoder Office
User xiazha0309
Language C++ 20 (gcc 12.2)
Score 575
Code Size 1064 Byte
Status AC
Exec Time 4577 ms
Memory 37548 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:33:30: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::vector<std::pair<long long int, long long int> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   33 |                 for(int j=0;j<g[r].size();j++)
      |                             ~^~~~~~~~~~~~
Main.cpp:13:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |                 scanf("%lld%lld",&t,&p);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~
Main.cpp:27:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   27 |                 scanf("%lld%lld",&l,&r);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 575 / 575
Status
AC × 2
AC × 78
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt, 01_random_49.txt, 01_random_50.txt, 01_random_51.txt, 01_random_52.txt, 01_random_53.txt, 01_random_54.txt, 01_random_55.txt, 01_random_56.txt, 01_random_57.txt, 01_random_58.txt, 01_random_59.txt, 01_random_60.txt, 01_random_61.txt, 01_random_62.txt, 01_random_63.txt, 01_random_64.txt, 01_random_65.txt, 01_random_66.txt, 01_random_67.txt, 01_random_68.txt, 01_random_69.txt, 02_handmade_68.txt, 02_handmade_69.txt, 02_handmade_70.txt, 02_handmade_71.txt, 02_handmade_72.txt, 02_handmade_73.txt, 02_handmade_74.txt, 02_handmade_75.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 2 ms 3776 KiB
00_sample_01.txt AC 2 ms 3592 KiB
01_random_02.txt AC 257 ms 37424 KiB
01_random_03.txt AC 252 ms 37444 KiB
01_random_04.txt AC 260 ms 37304 KiB
01_random_05.txt AC 247 ms 37340 KiB
01_random_06.txt AC 250 ms 37404 KiB
01_random_07.txt AC 256 ms 37404 KiB
01_random_08.txt AC 260 ms 37312 KiB
01_random_09.txt AC 249 ms 37336 KiB
01_random_10.txt AC 251 ms 37372 KiB
01_random_11.txt AC 258 ms 37344 KiB
01_random_12.txt AC 251 ms 37548 KiB
01_random_13.txt AC 258 ms 37428 KiB
01_random_14.txt AC 2040 ms 8136 KiB
01_random_15.txt AC 58 ms 16412 KiB
01_random_16.txt AC 94 ms 13476 KiB
01_random_17.txt AC 108 ms 11740 KiB
01_random_18.txt AC 114 ms 24812 KiB
01_random_19.txt AC 106 ms 16024 KiB
01_random_20.txt AC 156 ms 23288 KiB
01_random_21.txt AC 175 ms 25448 KiB
01_random_22.txt AC 1084 ms 5296 KiB
01_random_23.txt AC 1933 ms 5540 KiB
01_random_24.txt AC 2176 ms 5648 KiB
01_random_25.txt AC 2445 ms 7820 KiB
01_random_26.txt AC 2442 ms 7792 KiB
01_random_27.txt AC 2191 ms 11936 KiB
01_random_28.txt AC 906 ms 17180 KiB
01_random_29.txt AC 905 ms 17184 KiB
01_random_30.txt AC 278 ms 19264 KiB
01_random_31.txt AC 233 ms 22476 KiB
01_random_32.txt AC 257 ms 34372 KiB
01_random_33.txt AC 620 ms 5764 KiB
01_random_34.txt AC 253 ms 5404 KiB
01_random_35.txt AC 1018 ms 5344 KiB
01_random_36.txt AC 1928 ms 5356 KiB
01_random_37.txt AC 1769 ms 5604 KiB
01_random_38.txt AC 2151 ms 5572 KiB
01_random_39.txt AC 2170 ms 5556 KiB
01_random_40.txt AC 2354 ms 7128 KiB
01_random_41.txt AC 2349 ms 6908 KiB
01_random_42.txt AC 2261 ms 9756 KiB
01_random_43.txt AC 1581 ms 14528 KiB
01_random_44.txt AC 1605 ms 14496 KiB
01_random_45.txt AC 409 ms 18748 KiB
01_random_46.txt AC 257 ms 21880 KiB
01_random_47.txt AC 267 ms 31652 KiB
01_random_48.txt AC 2285 ms 13684 KiB
01_random_49.txt AC 3358 ms 18192 KiB
01_random_50.txt AC 227 ms 30368 KiB
01_random_51.txt AC 226 ms 30464 KiB
01_random_52.txt AC 230 ms 30432 KiB
01_random_53.txt AC 227 ms 30476 KiB
01_random_54.txt AC 1101 ms 5320 KiB
01_random_55.txt AC 1475 ms 5392 KiB
01_random_56.txt AC 2487 ms 10152 KiB
01_random_57.txt AC 2433 ms 11252 KiB
01_random_58.txt AC 2223 ms 14100 KiB
01_random_59.txt AC 1997 ms 15340 KiB
01_random_60.txt AC 1941 ms 15708 KiB
01_random_61.txt AC 1109 ms 5384 KiB
01_random_62.txt AC 1467 ms 5284 KiB
01_random_63.txt AC 2446 ms 10088 KiB
01_random_64.txt AC 2349 ms 11440 KiB
01_random_65.txt AC 2112 ms 13624 KiB
01_random_66.txt AC 1849 ms 15300 KiB
01_random_67.txt AC 1803 ms 15824 KiB
01_random_68.txt AC 65 ms 5388 KiB
01_random_69.txt AC 65 ms 5364 KiB
02_handmade_68.txt AC 65 ms 5504 KiB
02_handmade_69.txt AC 65 ms 5384 KiB
02_handmade_70.txt AC 1888 ms 31404 KiB
02_handmade_71.txt AC 2423 ms 29944 KiB
02_handmade_72.txt AC 1920 ms 28008 KiB
02_handmade_73.txt AC 3525 ms 33400 KiB
02_handmade_74.txt AC 4577 ms 30784 KiB
02_handmade_75.txt AC 3487 ms 27920 KiB