QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#379860#8576. Symphony in c++ majorucup-team027#TL 1ms3828kbC++232.5kb2024-04-06 19:35:022024-04-06 19:35:05

Judging History

你现在查看的是最新测评结果

  • [2024-04-06 19:35:05]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3828kb
  • [2024-04-06 19:35:02]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template <typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;

vector<string> nt = {"do", "re", "mi", "fa", "so", "la", "ti"};

struct node{
	vector<vector<int>> dp;

	node() {
		dp.resize(8, vector<int>(8, -1000000));
	}
};

const node unit;

node make_node(char ch) {
	node nd;
	nd.dp[7][7] = 0;

	for (int i = 0; i < 7; i++) {
		if (ch == nt[i][1]) nd.dp[i][7] = 0;
		if (ch == nt[i][0]) nd.dp[7][i] = 0;
	}

	return nd;
}

node merge(node a, node b) {
	node ans;

	for (int i = 0; i < 8; i++) {
		for (int j = 0; j < 8; j++) {
			ans.dp[i][j] = max(ans.dp[i][j], a.dp[i][j]);
			ans.dp[i][j] = max(ans.dp[i][j], b.dp[i][j]);
		}
	}
	
	for (int k = 0; k < 8; k++) {
		for (int i = 0; i < 8; i++) {
			for (int j = 0; j < 8; j++) {
				ans.dp[i][j] = max(ans.dp[i][j], a.dp[i][k] + b.dp[k][j] + 2*(k < 7));
			}
		}
	}

	return ans;
}

void print_node(node nd) {
	for (int i = 0; i < 8; i++) {
		for (int j = 0; j < 8; j++) {
			cout << nd.dp[i][j] << ' ';
		}
		cout << '\n';
	}
}

struct Tree {
	typedef node T;
	T f(T a, T b) { return merge(a, b); } // (any associative fn)
	vector<T> s; int n;
	Tree(int n = 0, T def = unit) : s(2*n, def), n(n) {}
	void update(int pos, char ch) {
		node val = make_node(ch);
		//cout << ch << '\n'; print_node(val);
		for (s[pos += n] = val; pos /= 2;)
			s[pos] = f(s[pos * 2], s[pos * 2 + 1]);
	}
	T query(int b, int e) { // query [b, e)
		T ra = unit, rb = unit;
		for (b += n, e += n; b < e; b /= 2, e /= 2) {
			if (b % 2) ra = f(ra, s[b++]);
			if (e % 2) rb = f(s[--e], rb);
		}
		return f(ra, rb);
	}
};

signed main() {
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n, q; cin >> n >> q;
	Tree tr(n);
	for (int i = 0; i < n; i++) {
		char c; cin >> c;
		tr.update(i, c);
	}

	while (q--) {
		char c; cin >> c;
		if (c == '?') {
			int l, r; cin >> l >> r; l--;
			node nd = tr.query(l, r);
			int ans = 0;
			for (int i = 0; i < 8; i++) {
				for (int j = 0; j < 8; j++) {
					ans = max(ans, nd.dp[i][j]);
				}
			}
			cout << (r-l)-ans << '\n';
		} else {
			int l, r; cin >> l >> r; l--;
			for (int i = l; i < r; i++) {
				char c; cin >> c;
				tr.update(i, c);
			}
		}
	}
	
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3828kb

input:

8 10
eldorado
? 1 3
? 1 8
# 6 7 it
? 1 8
# 3 3 t
? 1 8
# 1 8 streamer
? 1 8
# 1 8 symphony
? 1 8

output:

3
4
6
6
6
6

result:

ok 6 numbers

Test #2:

score: -100
Time Limit Exceeded

input:

500000 300000
rfsraltzititrofomloldlaefikdemaddaafmimiioiuaueiaedifacmxamttiiitaaltiiireexeafsaaraedosotlaioootaiosizlifiioadhnxiofsasaflleaiisstaotdlliulilxatrpdaraaraaoiaeoooiumwuumarlifesroloistedoaaieolisaoatamsredorrfiifaaidfeassfioaiasmstomasallsftsrfaiiirteomaeiirefldmlaoaofrxlaeuilioirafotoa...

output:


result: