Created
February 28, 2018 06:05
-
-
Save APwhitehat/9936f49242fc1372be0143629f8672c6 to your computer and use it in GitHub Desktop.
dump check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
#if DEBUG && !ONLINE_JUDGE | |
#include "debug.h" | |
#else | |
#define debug(args...) | |
#define DBG(x...) | |
#endif | |
typedef vector<int> vi;typedef vector<vi> vvi;typedef pair<int,int> ii;typedef pair<int,ii> iii;typedef vector<ii> vii;typedef vector<vii> vvii;typedef vector< iii > viii;typedef long long ll;typedef vector<ll> vll;typedef vector<vll> vvll;typedef vector<bool> vb;typedef long double ld;typedef map<int,int> mii;typedef map<string,int> msi; | |
#define pb push_back | |
#define PQ priority_queue | |
#define UM unordered_map | |
#define fi first | |
#define se second | |
#define sz(x) ((int)((x).size())) | |
#define FOR(i,a,b) for(auto i=(a);i<=(b);i++) | |
#define FORd(i,a,b) for(auto i=(a);i>=(b);i--) | |
#define REP(i,a) FOR(i,0,(a)-1) | |
#define all(x) (x).begin(),(x).end() | |
#define uni(x) (x).erase(unique(all(x)),(x).end()) | |
#define init(v,n) (v).clear();(v).resize(n) | |
#define initi(v,n,i) (v).clear();(v).resize(n,i) | |
#define sqr(x) ((x)*(x)) | |
#define LC(x) ((x)<<1) | |
#define RC(x) (((x)<<1)|1) | |
#define SUM(v) accumulate((v).begin(), (v).end(), 0LL) | |
#define MAX(v) *max_element((v).begin(), (v).end()) | |
#define MIN(v) *min_element((v).begin(), (v).end()) | |
#define EPS 1e-9 | |
#define EULER 2.7182818284 | |
#define MOD 1000000007 | |
const double PI=acos(-1.0); | |
template<typename T, typename U> inline void amin(T& x,U y) {if(x>y)x=y;} | |
template<typename T, typename U> inline void amax(T& x,U y) {if(x<y)x=y;} | |
#define N 100005 | |
//global variables | |
//global end | |
void prepro(){ | |
} | |
int main() | |
{ | |
ios::sync_with_stdio(false);cin.tie(0);cout.precision(17); | |
int teeeeee; | |
cin >> teeeeee; | |
while(teeeeee--){ | |
int n, q; | |
string s; | |
cin >> n >> q >> s; | |
vvi subB(n + 1); | |
map<string, bool> pre; | |
FOR(p, 1, n){ | |
string a = s.substr(0, p); | |
pre[a] = 1; | |
FOR(k, 1, p - 1){ | |
if(pre[s.substr(p - k, k)]) | |
subB[p].pb(k); | |
} | |
subB[p].pb(p); | |
} | |
REP(_, q){ | |
int p, k; | |
cin >> p >> k; | |
if(sz(subB[p]) < k) | |
cout << "-1\n"; | |
else | |
cout << subB[p][k - 1] << "\n"; | |
} | |
} | |
debug("\nRuntime = " + to_string((ld)clock()/CLOCKS_PER_SEC)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment