AtCoder Regular Contest 068

Submission #4014445

Source codeソースコード

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;

const int N=3e5+5;
const int M=1e5+5;
int n,m,now;
pair<int,int> p[N];

struct Tree_Array
{
	int c[N];
	int lowbit(int x)
	{
		return x&(-x);
	}
	
	void update(int pos,int add)
	{
		while(pos<=m)
		{
			c[pos]+=add;
			pos+=lowbit(pos);
		}
	}
	
	int query(int pos)
	{
		int ret=0;
		while(pos)
		{
			ret+=c[pos];
			pos-=lowbit(pos);
		}
		return ret;
	}
};
Tree_Array SS;

int cmp(pair<int,int> x,pair<int,int> y)
{
	return x.second-x.first<y.second-y.first;
}
void init()
{
	int i;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;++i)
		scanf("%d%d",&p[i].first,&p[i].second);
	sort(p+1,p+n+1,cmp);
}

void work()
{
	int i,j,ans;
	for(i=1;i<=m;++i)
	{
		ans=0;
		for(now;now<n&&p[now+1].second-p[now+1].first+1<=i;++now)
			SS.update(p[now+1].first,1),SS.update(p[now+1].second+1,-1);
		for(j=i;j<=m;j+=i) ans+=SS.query(j);
		printf("%d\n",ans+n-now);
	}
}

int main()
{
	init();work();
	return 0;
}

Submission

Task問題 E - Snuke Line
User nameユーザ名 hwk0518
Created time投稿日時
Language言語 C++ (GCC 5.4.1)
Status状態 AC
Score得点 700
Source lengthソースコード長 1113 Byte
File nameファイル名
Exec time実行時間 112 ms
Memory usageメモリ使用量 3712 KB

Compiler messageコンパイルメッセージ

./Main.cpp: In function ‘void init()’:
./Main.cpp:52:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&m);
^
./Main.cpp:54:41: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&p[i].first,&p[i].second);
^

Test case

Set

Set name Score得点 / Max score Cases
Sample - 00_example_01.txt,00_example_02.txt
All 700 / 700 00_example_01.txt,00_example_02.txt,01.txt,02.txt,03.txt,04.txt,05.txt,06.txt,07.txt,08.txt,09.txt,10.txt,11.txt,12.txt,13.txt,14.txt,15.txt,16.txt,17.txt,18.txt,19.txt,20.txt,21.txt,22.txt,23.txt,24.txt,25.txt,26.txt,27.txt,28.txt,29.txt,30.txt,31.txt,32.txt,33.txt,34.txt,35.txt,36.txt,37.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
00_example_01.txt AC 3 ms 2560 KB
00_example_02.txt AC 3 ms 2560 KB
01.txt AC 3 ms 2560 KB
02.txt AC 3 ms 2560 KB
03.txt AC 3 ms 2560 KB
04.txt AC 3 ms 2560 KB
05.txt AC 3 ms 2560 KB
06.txt AC 3 ms 2560 KB
07.txt AC 3 ms 2560 KB
08.txt AC 3 ms 2560 KB
09.txt AC 3 ms 2560 KB
10.txt AC 3 ms 2560 KB
11.txt AC 94 ms 2944 KB
12.txt AC 111 ms 3584 KB
13.txt AC 82 ms 2688 KB
14.txt AC 77 ms 2560 KB
15.txt AC 77 ms 2560 KB
16.txt AC 90 ms 2816 KB
17.txt AC 111 ms 3584 KB
18.txt AC 75 ms 2560 KB
19.txt AC 112 ms 3584 KB
20.txt AC 112 ms 3584 KB
21.txt AC 112 ms 3584 KB
22.txt AC 112 ms 3584 KB
23.txt AC 111 ms 3584 KB
24.txt AC 99 ms 3328 KB
25.txt AC 76 ms 2688 KB
26.txt AC 72 ms 2560 KB
27.txt AC 104 ms 3328 KB
28.txt AC 79 ms 2688 KB
29.txt AC 107 ms 3200 KB
30.txt AC 79 ms 2688 KB
31.txt AC 97 ms 3328 KB
32.txt AC 77 ms 2688 KB
33.txt AC 73 ms 2560 KB
34.txt AC 99 ms 3712 KB
35.txt AC 99 ms 3712 KB
36.txt AC 3 ms 2560 KB
37.txt AC 23 ms 2816 KB