Submission #947452

# Submission time Handle Problem Language Result Execution time Memory
947452 2024-03-16T08:18:53 Z pcc Selling RNA Strands (JOI16_selling_rna) C++17
100 / 100
234 ms 57684 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
#define bs basic_string<int>

const int mxn = 1e5+10;


int N,Q;
basic_string<int> arr[mxn];
vector<pair<basic_string<int>,int>> op[mxn];
int ans[mxn];

struct node{
	int ch[4];
	int dp;
};

int ppp = 0;
int newnode(){
	return ++ppp;
}

node trie[mxn*100];
int rt;

void add(bs s){
	int now = rt;
	for(auto &i:s){
		if(!trie[now].ch[i])trie[now].ch[i] = newnode();
		now = trie[now].ch[i];
		trie[now].dp++;
	}
	return;
}
int getans(basic_string<int> s){
	int now = rt;
	for(auto &i:s){
		now = trie[now].ch[i];
	}
	return trie[now].dp;
}

basic_string<int> conv(string s){
	basic_string<int> re;
	for(auto &i:s){
		if(i == 'A')re += 0;
		else if(i == 'C')re += 1;
		else if(i == 'G')re += 2;
		else re += 3;
	}
	return re;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	rt = newnode();
	cin>>N>>Q;
	for(int i = 1;i<=N;i++){
		string s;
		cin>>s;
		arr[i] = conv(s);
	}
	sort(arr+1,arr+N+1);
	for(int i = 1;i<=Q;i++){
		string sa,sb;
		cin>>sa>>sb;
		auto ta = conv(sa),tb = conv(sb);
		reverse(tb.begin(),tb.end());
		auto lit = lower_bound(arr+1,arr+N+1,ta)-arr;
		ta.back()++;
		auto rit = lower_bound(arr+1,arr+N+1,ta)-arr;
		op[lit].push_back(make_pair(tb,i));
		op[rit].push_back(make_pair(tb,-i));
	}
	for(int i = N;i>=1;i--){
		reverse(arr[i].begin(),arr[i].end());
		add(arr[i]);
		for(auto &j:op[i]){
			if(j.sc>0){
				ans[j.sc] += getans(j.fs);
			}
			else ans[-j.sc] -= getans(j.fs);
		}
	}
	for(int i = 1;i<=Q;i++)cout<<ans[i]<<'\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Correct 2 ms 6840 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 97 ms 56792 KB Output is correct
2 Correct 101 ms 55832 KB Output is correct
3 Correct 60 ms 34432 KB Output is correct
4 Correct 60 ms 34396 KB Output is correct
5 Correct 65 ms 44720 KB Output is correct
6 Correct 57 ms 44808 KB Output is correct
7 Correct 81 ms 31268 KB Output is correct
8 Correct 88 ms 55892 KB Output is correct
9 Correct 101 ms 54668 KB Output is correct
10 Correct 67 ms 40880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 11964 KB Output is correct
2 Correct 25 ms 11696 KB Output is correct
3 Correct 33 ms 11664 KB Output is correct
4 Correct 23 ms 10020 KB Output is correct
5 Correct 27 ms 11620 KB Output is correct
6 Correct 36 ms 11792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Correct 2 ms 6840 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 97 ms 56792 KB Output is correct
9 Correct 101 ms 55832 KB Output is correct
10 Correct 60 ms 34432 KB Output is correct
11 Correct 60 ms 34396 KB Output is correct
12 Correct 65 ms 44720 KB Output is correct
13 Correct 57 ms 44808 KB Output is correct
14 Correct 81 ms 31268 KB Output is correct
15 Correct 88 ms 55892 KB Output is correct
16 Correct 101 ms 54668 KB Output is correct
17 Correct 67 ms 40880 KB Output is correct
18 Correct 34 ms 11964 KB Output is correct
19 Correct 25 ms 11696 KB Output is correct
20 Correct 33 ms 11664 KB Output is correct
21 Correct 23 ms 10020 KB Output is correct
22 Correct 27 ms 11620 KB Output is correct
23 Correct 36 ms 11792 KB Output is correct
24 Correct 122 ms 53864 KB Output is correct
25 Correct 141 ms 57684 KB Output is correct
26 Correct 113 ms 50768 KB Output is correct
27 Correct 79 ms 38484 KB Output is correct
28 Correct 234 ms 35156 KB Output is correct
29 Correct 177 ms 34080 KB Output is correct