제출 #243887

#제출 시각아이디문제언어결과실행 시간메모리
243887_7_7_Gift (IZhO18_nicegift)C++14
100 / 100
1522 ms196232 KiB
#include <bits/stdc++.h>                                           
 
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;                             
 
 
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 1e6 + 11;
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;


vector < pair < int, vi > > ans;
int n, m, k, a[N], sum;
set < int > pos, q;
vpii add, del;
vi Pos;


void f (int l, int r, int x) {
//	cerr << l << ' ' << r << ' ' << x << endl;
	pos.insert(l);
	pos.insert(r + 1);
	add.pb({l, x});
	del.pb({r + 1, x});
}

main () {
	fastio
	scanf("%lld%lld", &n, &k);
	for (int i = 1; i <= n; ++i) {
		scanf("%lld", &a[i]);
		sum += a[i];
	}

	m = sum / k;
	if ((sum % k) || m < *max_element(a + 1, a + 1 + n)) {
		cout << -1;
		return 0;
	}

	int cur = 1;
	for (int i = 1; i <= n; ++i) {
		if (cur + a[i] - 1 > m) {
			f(cur, m, i);
			f(1, cur + a[i] - 1 - m, i);
		} else
			f(cur, cur + a[i] - 1, i);

		cur += a[i];
		if (cur > m)
			cur -= m;
	}

	sort(all(add));
	sort(all(del));


	int j1 = 0, j2 = 0;
	for (auto i : pos)
		Pos.pb(i);


	for (int j = 0; j < sz(Pos); ++j) {
		int i = Pos[j];
		while (j2 < sz(del) && del[j2].f == i) {
			 q.erase(del[j2].s);
			 ++j2;
		}

		while (j1 < sz(add) && add[j1].f == i) {
			q.insert(add[j1].s);
			++j1;
		}

		if (j < sz(Pos) - 1) {
			vi tmp;
			for (auto x : q)
				tmp.pb(x);
			ans.pb({Pos[j + 1] - Pos[j], tmp});
//			cerr << Pos[j + 1] << ' ' << Pos[j] << endl;	
		}
	}

	printf("%lld\n", sz(ans));
	for (auto v : ans) {
		printf("%lld ", v.f);
		for (auto x : v.s)
			printf("%lld ", x);
		printf("\n");
	}
}

컴파일 시 표준 에러 (stderr) 메시지

nicegift.cpp:55:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
nicegift.cpp: In function 'int main()':
nicegift.cpp:57:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld", &n, &k);
  ~~~~~^~~~~~~~~~~~~~~~~~~~
nicegift.cpp:59:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &a[i]);
   ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...