提交记录 3891


用户 题目 状态 得分 用时 内存 语言 代码长度
whzzt noi18a. 【NOI2018】归程 Accepted 100 1.126 s 71112 KB C++11 3.76 KB
提交时间 评测时间
2018-07-18 19:36:58 2020-07-31 21:58:12
#include <bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define ALL(a) a.begin(), a.end()
#define lowbit(x) ((x) & -(x))

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, int> pii;
typedef pair<int, int> pi;
typedef vector<int> VI;

namespace io {
	const int L = (1 << 21) + 1;
	char ibuf[L], *iS, *iT, obuf[L], *oS = obuf, *oT = obuf + L - 1, c, qu[55]; int f, qr;
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, L, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush () { fwrite (obuf, 1, oS - obuf, stdout); oS = obuf; }
	inline void putc (char x) { *oS ++ = x; if (oS == oT) flush (); }
	template <class I> inline void gi (I & x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;
	}
	template <class I> inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0', x /= 10;
		while (qr) putc (qu[qr --]);
	}
	inline char read () {
		for (c = gc(); c < 'a' || c > 'z'; c = gc());
		return c;
	}
	inline void gs (char *s) {
		int l;
		for (c = gc(); c < 'a' || c > 'z'; c = gc());
		for (l = 0; c <= 'z' && c >= 'a'; c = gc()) s[l] = c, ++l;
		s[l] = 0;
	}
	inline void ps (const char *s) {
		int l = strlen(s), i;
		for (i = 0; i < l; i ++) putc(s[i]);
	}
	struct IOC { ~ IOC () { flush (); } } _ioc_;
} ;
using io::gi;
using io::gs;
using io::ps;
using io::putc;
using io::read;
using io::print;

template <class T> inline bool chkmin(T &a, T b) { return b < a ? a = b, true : false; }
template <class T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; }

const int N = 2e5 + 5, M = 4e5 + 5, inf = 2e9, G = 20;

struct edge_t{
	int u, v, c;
	edge_t() { u = v = c = 0; }
	edge_t(int u, int v, int c):u(u), v(v), c(c) {}
	bool operator < (const edge_t &a) const { return c < a.c; }
} ;

vector <pi> adj[N];
vector <edge_t> all;
priority_queue <pi, vector<pi>, greater<pi> > Q;
int ans, test, n, m, cnt, q, op, hi, dis[N], fa[M][G], tim[M], res[M], par[M];
int find(int u){ return par[u] == u ? u : par[u] = find(par[u]); }
bool vis[N];

int main(){
	freopen("return.in", "r", stdin), freopen("return.out", "w", stdout);
	for (gi(test); test; --test) {
		int i, u, v, l, a;
		gi(n), gi(m);
		for (i = 1; i <= m; i ++) {
			gi(u), gi(v), gi(l), gi(a);
			adj[u].pb(pi(v, l)), adj[v].pb(pi(u, l));
			all.pb(edge_t(u, v, -a));
		}
		for (i = 1; i <= n; i ++) dis[i] = inf;
		Q.push(pi(dis[1] = 0, 1));
		while (Q.size()) {
			pi cur = Q.top(); Q.pop();
			if (vis[u = cur.se]) continue;
			vis[u] = true;
			for (i = 0; i < adj[u].size(); i ++) {
				pi e = adj[u][i];
				if (dis[v = e.fi] > dis[u] + e.se) {
					dis[v] = dis[u] + e.se;
					Q.push(pi(dis[v], v));
				}
			}
		}
		for (i = 1; i <= n; i ++) par[i] = i, res[i] = dis[i], tim[i] = -inf;
		cnt = n;
		sort(all.begin(), all.end());
		for (i = 0; i < all.size(); i ++) {
			u = find(all[i].u), v = find(all[i].v);
			if (u == v) continue;
			++cnt, fa[u][0] = par[u] = cnt, fa[v][0] = par[v] = cnt, par[cnt] = cnt;
			tim[cnt] = all[i].c, res[cnt] = min(res[u], res[v]);
		}
		for (u = cnt; u >= 1; u --) for (i = 0; fa[u][i]; fa[u][i + 1] = fa[fa[u][i]][i], ++i);
		for (ans = 0, gi(q), gi(op), gi(hi); q; q --) {
			gi(u), gi(v);
			u = (u + op * ans - 1) % n + 1;
			if (u <= 0) u += n;
			v = (v + op * ans) % (hi + 1);
			for (i = 18; i >= 0; i --) if (tim[fa[u][i]] < -v) u = fa[u][i];
			print(ans = res[u]), putc('\n');
		}
		
		all.clear();
		for (u = 1; u <= n; u ++) adj[u].clear(), dis[u] = vis[u] = 0;
		for (u = 1; u <= cnt; u ++) {
			par[u] = res[u] = tim[u] = 0;
			memset(fa[u], 0, sizeof(fa[u]));
		}
	}
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #1666.92 us4 MB + 660 KBAcceptedScore: 5

Testcase #2679.16 us4 MB + 668 KBAcceptedScore: 5

Testcase #3743.7 us4 MB + 692 KBAcceptedScore: 5

Testcase #4833.51 us4 MB + 708 KBAcceptedScore: 5

Testcase #52.977 ms5 MB + 316 KBAcceptedScore: 5

Testcase #6672.758 ms64 MB + 504 KBAcceptedScore: 5

Testcase #72.176 ms5 MB + 244 KBAcceptedScore: 5

Testcase #82.157 ms5 MB + 248 KBAcceptedScore: 5

Testcase #92.16 ms5 MB + 244 KBAcceptedScore: 5

Testcase #10508.239 ms56 MB + 384 KBAcceptedScore: 5

Testcase #11508.631 ms56 MB + 388 KBAcceptedScore: 5

Testcase #12798.083 ms65 MB + 684 KBAcceptedScore: 5

Testcase #13797.511 ms65 MB + 516 KBAcceptedScore: 5

Testcase #14797.355 ms64 MB + 952 KBAcceptedScore: 5

Testcase #153.449 ms5 MB + 420 KBAcceptedScore: 5

Testcase #163.45 ms5 MB + 424 KBAcceptedScore: 5

Testcase #17797.681 ms65 MB + 196 KBAcceptedScore: 5

Testcase #18798.332 ms65 MB + 480 KBAcceptedScore: 5

Testcase #191.122 s69 MB + 456 KBAcceptedScore: 5

Testcase #201.126 s68 MB + 976 KBAcceptedScore: 5


Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 10:28:21 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠