結果

問題 No.2880 Max Sigma Mod
ユーザー 👑 kmjpkmjp
提出日時 2024-09-08 22:21:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 849 ms / 3,000 ms
コード長 1,940 bytes
コンパイル時間 2,158 ms
コンパイル使用メモリ 203,288 KB
実行使用メモリ 19,972 KB
最終ジャッジ日時 2024-09-08 22:21:41
合計ジャッジ時間 16,364 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
19,716 KB
testcase_01 AC 7 ms
19,692 KB
testcase_02 AC 10 ms
19,884 KB
testcase_03 AC 10 ms
19,972 KB
testcase_04 AC 7 ms
19,748 KB
testcase_05 AC 655 ms
19,696 KB
testcase_06 AC 539 ms
19,712 KB
testcase_07 AC 421 ms
19,820 KB
testcase_08 AC 362 ms
19,840 KB
testcase_09 AC 227 ms
19,692 KB
testcase_10 AC 213 ms
19,692 KB
testcase_11 AC 507 ms
19,744 KB
testcase_12 AC 134 ms
19,732 KB
testcase_13 AC 119 ms
19,820 KB
testcase_14 AC 433 ms
19,880 KB
testcase_15 AC 815 ms
19,816 KB
testcase_16 AC 838 ms
19,756 KB
testcase_17 AC 849 ms
19,708 KB
testcase_18 AC 790 ms
19,776 KB
testcase_19 AC 833 ms
19,720 KB
testcase_20 AC 80 ms
19,748 KB
testcase_21 AC 287 ms
19,684 KB
testcase_22 AC 500 ms
19,856 KB
testcase_23 AC 55 ms
19,808 KB
testcase_24 AC 341 ms
19,728 KB
testcase_25 AC 634 ms
19,748 KB
testcase_26 AC 715 ms
19,796 KB
testcase_27 AC 660 ms
19,780 KB
testcase_28 AC 702 ms
19,732 KB
testcase_29 AC 351 ms
19,700 KB
testcase_30 AC 8 ms
19,804 KB
testcase_31 AC 6 ms
19,736 KB
testcase_32 AC 83 ms
19,732 KB
testcase_33 AC 7 ms
19,788 KB
testcase_34 AC 7 ms
19,732 KB
testcase_35 AC 6 ms
19,732 KB
testcase_36 AC 85 ms
19,924 KB
testcase_37 AC 7 ms
19,684 KB
testcase_38 AC 7 ms
19,756 KB
testcase_39 AC 7 ms
19,884 KB
testcase_40 AC 7 ms
19,732 KB
testcase_41 AC 85 ms
19,708 KB
testcase_42 AC 7 ms
19,720 KB
testcase_43 AC 7 ms
19,704 KB
testcase_44 AC 7 ms
19,772 KB
testcase_45 AC 7 ms
19,744 KB
testcase_46 AC 7 ms
19,836 KB
testcase_47 AC 84 ms
19,880 KB
testcase_48 AC 7 ms
19,728 KB
testcase_49 AC 8 ms
19,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,M;

template<class V, int ME> class BIT_r {
public:
	V bit[2][1<<ME];
	BIT_r(){clear();};
	void clear() {ZERO(bit);};
	
	void update(int entry, V val0, V val1) {
		entry++;
		while(entry <= 1<<ME) bit[0][entry-1]+=val0, bit[1][entry-1] += val1, entry += entry & -entry;
	}
	V total(int entry) {
		if(entry<0) return 0;
		int e=entry++;
		V v0=0,v1=0;
		while(entry>0) v0+=bit[0][entry-1], v1+=bit[1][entry-1], entry -= entry & -entry;
		return e*v0+v1;
	}
	void add(int L, int R, V val) { // add val to L<=x<=R
		update(L,val,-val*(L-1));
		update(R+1,-val,val*R);
	}
	int lower_bound(V val) { //単調増加の時のみ使える
		V v0=0,v1=0; int i,ent=0;
		for(i=ME-1;i>=0;i--) {
			if((ent+(1<<i)-1)*(v0+bit[0][ent+(1<<i)-1])+(v1+bit[1][ent+(1<<i)-1])<val) {
				v0+=bit[0][ent+(1<<i)-1];
				v1+=bit[1][ent+(1<<i)-1];
				ent+=(1<<i);
			}
		}
		return ent;
	}
};
BIT_r<ll,20> bt;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	ll ret=0;
	for(i=2;i<=M;i++) {
		for(x=1;x<=N;x+=i) {
			bt.add(x,x+i-2,1);
			bt.add(x+i-1,x+i-1,-(i-1));
		}
	}
	for(x=1;x<=N;x++) {
		ret=max(ret,bt.total(x));
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0