Submission #1610627


Source Code Expand

#ifdef DEBUG
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <cassert>
#include <sstream>
#include <fstream>
#include <functional>
#include <set>
#include <bitset>
#include <string>
#include <utility>
#include <queue>
#include <deque>
#include <vector>
#include <map>
#else
#include <bits/stdc++.h>
#endif

#ifdef DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif

#define rep(i, n) for (int i = 0, i##_end_ = (n); i < i##_end_; ++i)
#define per(i, n) for (int i = (n) - 1; i >= 0; --i)
#define forn(i, l, r) for (int i = (l), i##_end_ = (r); i <= i##_end_; ++i)
#define nrof(i, r, l) for (int i = (r), i##_end_ = (l); i >= i##_end_; --i)
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define SZ(x) (int)((x).size())
#define ALL(x) (x).begin(), (x).end()

using namespace std;

typedef vector<int> vi;

typedef pair<int, int> pii;

typedef long long LL;

template<typename T> inline bool chkmax(T &x, const T &y) {
	return x < y ? x = y, 1 : 0;
}

#ifdef DEBUG
char *input_file, *output_file;
#endif

struct IO {
	static const int maxn = (1 << 25) + 10;

	char a[maxn], *s, b[maxn], *t;

	void INPUT() {
		s = a;
		t = b;
		#ifdef DEBUG
		FILE *f = fopen(input_file, "r");
		a[fread(a, 1, sizeof a, f)] = 0;
		#else
		a[fread(a, 1, sizeof a, stdin)] = 0;
		#endif
	}

	void OUTPUT() {
#ifdef DEBUG
		FILE *f = fopen(output_file, "w");
		fwrite(b, 1, t - b, f);
#else
		fwrite(b, 1, t - b, stdout);
#endif
	}

	operator int() {
		int x = 0;
		while(*s != '-' && (*s < '0' || *s > '9')) {
			++s;
		}
		bool f = 0;
		if(*s == '-') {
			f = 1;
			++s;
		}
		while(*s >= '0' && *s <= '9') {
			(x *= 10) += *s - '0';
			++s;
		}
		if(f) {
			x = -x;
		}
		return x;
	}

	operator LL() {
		LL x = 0;
		while(*s != '-' && (*s < '0' || *s > '9')) {
			++s;
		}
		bool f = 0;
		if(*s == '-') {
			f = 1;
			++s;
		}
		while(*s >= '0' && *s <= '9') {
			(x *= 10) += *s - '0';
			++s;
		}
		if(f) {
			x = -x;
		}
		return x;
	}

	operator char() {
		while(*s <= 32) {
			++s;
		}
		char ret = *s;
		++s;
		return ret;
	}

	inline void out(int x) {
		if(!x) {
			*t++ = '0';
			return;
		}
		if(x < 0) {
			*t++ = '-';
			x = -x;
		}
		static char c[20], *i;
		i = c;
		while(x) {
			int y = x / 10;
			*i++ = x - y * 10 + '0';
			x = y;
		}
		while(i != c) {
			*t++ = *--i;
		}
		return;
	}

	inline void out(int x, char C) {
		if(!x) {
			*t++ = '0';
			*t++ = C;
			return;
		}
		if(x < 0) {
			*t++ = '-';
			x = -x;
		}
		static char c[20], *i;
		i = c;
		while(x) {
			int y = x / 10;
			*i++ = x - y * 10 + '0';
			x = y;
		}
		while(i != c) {
			*t++ = *--i;
		}
		*t++ = C;
		return;
	}

	inline void out(LL x) {
		if(!x) {
			*t++ = '0';
			return;
		}
		if(x < 0) {
			*t++ = '-';
			x = -x;
		}
		static char c[20], *i;
		i = c;
		while(x) {
			LL y = x / 10;
			*i++ = x - y * 10 + '0';
			x = y;
		}
		while(i != c) {
			*t++ = *--i;
		}
		return;
	}

	inline void out(LL x, char C) {
		if(!x) {
			*t++ = '0';
			*t++ = '.';
			*t++ = '0';
			*t++ = C;
			return;
		}
		if(x < 0) {
			*t++ = '-';
			x = -x;
		}
		static char c[20], *i;
		i = c;
		while(x) {
			LL y = x / 10;
			*i++ = x - y * 10 + '0';
			x = y;
		}
		while(i != c) {
			*t++ = *--i;
		}
		*t++ = '.';
		*t++ = '0';
		*t++ = C;
		return;
	}

	inline void out(char c) {
		*t++ = c;
		return;
	}
}io;

void Main();

int main(int argc, char *argv[]) {
#ifdef DEBUG
	input_file = argv[1];
	output_file = argv[2];
#endif
	io.INPUT();
	Main();
	io.OUTPUT();
	return 0;
}

//---------------------------------------------------------------------------------------head---------------------------------------------------------------------------------------

const int maxn = 1e5 + 100;

int n, m;
LL K;
int x[maxn], p[maxn], to[maxn], q[maxn];
LL y[maxn];
bool vis[maxn];

void Main() {
	n = io;
	forn(i, 1, n) {
		x[i] = io;
		p[i] = i;
	}
	m = io;
	K = io;
	forn(i, 1, m) {
		int x = io;
		swap(p[x], p[x - 1]);
	}
	forn(i, 1, n - 1) {
		to[p[i]] = i;
		p[i] = i;
	}
	forn(i, 1, n - 1) {
		if(!vis[i]) {
			int k = 0;
			for (int j = i; !vis[j]; j = to[j]) {
				q[k++] = j;
				vis[j] = 1;
			}
			rep(i, k) {
				int j = (K + i) % k;
				y[q[j]] = x[q[i] + 1] - x[q[i]];
			}
		}
	}
	io.out(y[0] = x[1], '\n');
	forn(i, 1, n - 1) {
		y[i] += y[i - 1];
		io.out(y[i], '\n');
	}
	return;
}

Submission Info

Submission Time
Task C - Rabbit Exercise
User OMTWOCZWEIXVI
Language C++14 (GCC 5.4.1)
Score 800
Code Size 4667 Byte
Status AC
Exec Time 12 ms
Memory 7552 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 800 / 800
Status
AC × 3
AC × 29
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt
Case Name Status Exec Time Memory
0_00.txt AC 2 ms 4352 KB
0_01.txt AC 2 ms 4352 KB
0_02.txt AC 2 ms 4352 KB
1_00.txt AC 2 ms 4352 KB
1_01.txt AC 2 ms 4352 KB
1_02.txt AC 11 ms 7168 KB
1_03.txt AC 12 ms 7552 KB
1_04.txt AC 9 ms 6528 KB
1_05.txt AC 2 ms 4352 KB
1_06.txt AC 2 ms 4352 KB
1_07.txt AC 2 ms 4352 KB
1_08.txt AC 2 ms 4352 KB
1_09.txt AC 2 ms 4352 KB
1_10.txt AC 2 ms 4352 KB
1_11.txt AC 3 ms 4480 KB
1_12.txt AC 2 ms 4352 KB
1_13.txt AC 3 ms 4352 KB
1_14.txt AC 2 ms 4352 KB
1_15.txt AC 3 ms 4608 KB
1_16.txt AC 2 ms 4480 KB
1_17.txt AC 7 ms 5504 KB
1_18.txt AC 8 ms 5888 KB
1_19.txt AC 10 ms 6400 KB
1_20.txt AC 5 ms 4992 KB
1_21.txt AC 6 ms 5120 KB
1_22.txt AC 10 ms 6400 KB
1_23.txt AC 10 ms 6784 KB
1_24.txt AC 8 ms 6144 KB
1_25.txt AC 7 ms 6400 KB