AtCoder Regular Contest 068

Submission #4014356

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;
const int T=1e7+5;
int n,m,st[M],en[M];
pair<int,int> p[N];

struct Chairman_Tree
{
	int seg_tot,rt[N];
	struct node
	{
		int lsn,rsn,cnt;
	};
	node seg[T];
	
	void update(int &rt,int las,int l,int r,int pos)
	{
		seg[rt=++seg_tot]=seg[las];
		++seg[rt].cnt;
		if(l==r) return;
		int mid=(l+r)>>1;
		if(pos<=mid) update(seg[rt].lsn,seg[las].lsn,l,mid,pos);
		else update(seg[rt].rsn,seg[las].rsn,mid+1,r,pos);
	}
	
	int query(int rt,int las,int l,int r,int L,int R)
	{
		if(L<=l&&r<=R) return seg[rt].cnt-seg[las].cnt;
		int mid=(l+r)>>1;int ret=0;
		if(L<=mid) ret+=query(seg[rt].lsn,seg[las].lsn,l,mid,L,R);
		if(R>mid) ret+=query(seg[rt].rsn,seg[las].rsn,mid+1,r,L,R);
		return ret;
	}
};
Chairman_Tree SS;

void init()
{
	int i,now=0;
	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);
	
	for(i=1;i<=m;++i)
	{
		st[i]=now+1;
		while(p[now+1].first==i) ++now;
		en[i]=now;
	}
	
	for(i=1;i<=n;++i)
		SS.update(SS.rt[i],SS.rt[i-1],1,m,p[i].second);
}

int calc(int x,int y,int l,int r)
{
	return SS.query(SS.rt[en[y]],SS.rt[st[x]-1],1,m,l,r);
}

void work()
{
	int i,j,ans=0;
	for(i=1;i<=m;++i)
	{
		ans=0;
		for(j=i;j<=m;j+=i)
			ans+=calc(j-i+1,j,j,m);
		printf("%d\n",ans);
	}
}

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ソースコード長 1546 Byte
File nameファイル名
Exec time実行時間 314 ms
Memory usageメモリ使用量 69120 KB

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

./Main.cpp: In function ‘void init()’:
./Main.cpp:49: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:51: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 4352 KB
00_example_02.txt AC 3 ms 4352 KB
01.txt AC 3 ms 4352 KB
02.txt AC 3 ms 4480 KB
03.txt AC 3 ms 4352 KB
04.txt AC 3 ms 4352 KB
05.txt AC 3 ms 4352 KB
06.txt AC 3 ms 4352 KB
07.txt AC 3 ms 4352 KB
08.txt AC 3 ms 4352 KB
09.txt AC 3 ms 4352 KB
10.txt AC 3 ms 4352 KB
11.txt AC 177 ms 64128 KB
12.txt AC 300 ms 69120 KB
13.txt AC 114 ms 55552 KB
14.txt AC 100 ms 49408 KB
15.txt AC 100 ms 49408 KB
16.txt AC 155 ms 61952 KB
17.txt AC 300 ms 68992 KB
18.txt AC 94 ms 45312 KB
19.txt AC 306 ms 69120 KB
20.txt AC 304 ms 69120 KB
21.txt AC 314 ms 69120 KB
22.txt AC 306 ms 69120 KB
23.txt AC 300 ms 69120 KB
24.txt AC 300 ms 68736 KB
25.txt AC 119 ms 57728 KB
26.txt AC 99 ms 51456 KB
27.txt AC 311 ms 68864 KB
28.txt AC 125 ms 57728 KB
29.txt AC 302 ms 68864 KB
30.txt AC 127 ms 57728 KB
31.txt AC 246 ms 69120 KB
32.txt AC 110 ms 57728 KB
33.txt AC 97 ms 51456 KB
34.txt AC 273 ms 69120 KB
35.txt AC 274 ms 69120 KB
36.txt AC 3 ms 4352 KB
37.txt AC 141 ms 5248 KB