fork download
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define forn(i,n) for(int i=0;i<(int)(n); i++)
  6. #define forsn(i,s,n) for(int i=(s);i<(int)(n); i++)
  7. #define debug(x) cout << #x << " = " << x << endl
  8. #define pb push_back
  9. #define mp make_pair
  10.  
  11. typedef long long tint;
  12.  
  13. vector<int> rmq, arr;
  14.  
  15. int NEUTRO=-1;
  16.  
  17. int res(int nodo, int l, int r, int i, int j){
  18. if(j<=l || i>=r)return NEUTRO;
  19. if(i<=l && j>=r){
  20. return rmq[nodo];
  21. }
  22. int i1=res(nodo*2, l, (l+r)/2, i, j);
  23. int i2=res(nodo*2+1, (l+r)/2, r, i, j);
  24. if(i1==-1)return i2;
  25. if(i2==-1)return i1;
  26. if(arr[i1]>=arr[i2])return i1;
  27. return i2;
  28. }
  29.  
  30.  
  31.  
  32. void build(){
  33. for(int i=0; i<2*(int)(arr.size()); i++)rmq.push_back(0);
  34. for(int i=(int)(arr.size()); i<2*(int)(arr.size()); i++){
  35. rmq[i]=i-arr.size();
  36. }
  37. for(int i=(int)arr.size()-1; i>=1; i--){
  38. if(arr[rmq[2*i]]>=arr[rmq[2*i+1]]){
  39. rmq[i]=rmq[2*i];
  40. }else{
  41. rmq[i]=rmq[2*i+1];
  42. }
  43. }
  44. }
  45.  
  46. int CountPS(char str[], int n){
  47.  
  48. int dp[n][n];
  49. memset(dp, 0, sizeof(dp));
  50. bool P[n][n];
  51. memset(P, false , sizeof(P));
  52. for (int i= 0; i< n; i++)
  53. P[i][i] = true;
  54.  
  55. for (int i=0; i<n-1; i++){
  56. if (str[i] == str[i+1]){
  57. P[i][i+1] = true;
  58. dp[i][i+1] = 1 ;
  59. }
  60. }
  61. for (int gap=2 ; gap<n; gap++){
  62. for (int i=0; i<n-gap; i++){
  63. int j = gap + i;
  64. if (str[i] == str[j] && P[i+1][j-1] )
  65. P[i][j] = true;
  66.  
  67. if (P[i][j] == true)
  68. dp[i][j] = dp[i][j-1] + dp[i+1][j] + 1 - dp[i+1][j-1];
  69. else
  70. dp[i][j] = dp[i][j-1] + dp[i+1][j] - dp[i+1][j-1];
  71. }
  72. }
  73.  
  74. return dp[0][n-1];
  75. }
  76.  
  77. void solve(){
  78. arr.clear();
  79. rmq.clear();
  80. int n,m;
  81. scanf("%d %d", &n, &m);
  82. map<string, int> id;
  83. forn(i, n){
  84. char tmp[44];
  85. scanf("%s", tmp);
  86. int nu=CountPS(tmp, sizeof(tmp));
  87. arr.pb(nu+sizeof(tmp));
  88. id[tmp]=i;
  89. }
  90. int p2=1;
  91. while(p2<(int)arr.size())p2*=2;
  92. while(p2>(int)arr.size())arr.pb(0);
  93. build();
  94. while(m--){
  95. char s1[44], s2[44];
  96. scanf("%s %s", s1, s2);
  97. int l=id[s1];
  98. int r=id[s2];
  99. r++;
  100. cout<<res(1, 0, (int)arr.size(), l, r)+1<<endl;
  101. }
  102. }
  103.  
  104.  
  105. int main(){
  106. int T;
  107. scanf("%d", &T);
  108. while(T--)solve();
  109. }
  110.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: illegal character: '#'
#include<bits/stdc++.h>
^
Main.java:1: error: class, interface, or enum expected
#include<bits/stdc++.h>
        ^
Main.java:5: error: illegal character: '#'
#define forn(i,n) for(int i=0;i<(int)(n); i++)
^
Main.java:5: error: class, interface, or enum expected
#define forn(i,n) for(int i=0;i<(int)(n); i++)
        ^
Main.java:5: error: class, interface, or enum expected
#define forn(i,n) for(int i=0;i<(int)(n); i++)
                              ^
Main.java:5: error: class, interface, or enum expected
#define forn(i,n) for(int i=0;i<(int)(n); i++)
                                          ^
Main.java:6: error: illegal character: '#'
#define forsn(i,s,n) for(int i=(s);i<(int)(n); i++)
^
Main.java:6: error: class, interface, or enum expected
#define forsn(i,s,n) for(int i=(s);i<(int)(n); i++)
                                   ^
Main.java:6: error: class, interface, or enum expected
#define forsn(i,s,n) for(int i=(s);i<(int)(n); i++)
                                               ^
Main.java:7: error: illegal character: '#'
#define debug(x) cout << #x << " = "  << x << endl
^
Main.java:7: error: illegal character: '#'
#define debug(x) cout << #x << " = "  << x << endl
                         ^
Main.java:8: error: illegal character: '#'
#define pb push_back
^
Main.java:9: error: illegal character: '#'
#define mp make_pair
^
Main.java:13: error: class, interface, or enum expected
vector<int> rmq, arr;
^
Main.java:15: error: class, interface, or enum expected
int NEUTRO=-1;
^
Main.java:17: error: class, interface, or enum expected
int res(int nodo, int l, int r, int i, int j){
^
Main.java:19: error: class, interface, or enum expected
	if(i<=l && j>=r){
	^
Main.java:21: error: class, interface, or enum expected
	}
	^
Main.java:23: error: class, interface, or enum expected
	int i2=res(nodo*2+1, (l+r)/2, r, i, j);
	^
Main.java:24: error: class, interface, or enum expected
	if(i1==-1)return i2;
	^
Main.java:25: error: class, interface, or enum expected
	if(i2==-1)return i1;
	^
Main.java:26: error: class, interface, or enum expected
	if(arr[i1]>=arr[i2])return i1;
	^
Main.java:27: error: class, interface, or enum expected
	return i2;
	^
Main.java:28: error: class, interface, or enum expected
}
^
Main.java:33: error: class, interface, or enum expected
	for(int i=0; i<2*(int)(arr.size()); i++)rmq.push_back(0);
	             ^
Main.java:33: error: class, interface, or enum expected
	for(int i=0; i<2*(int)(arr.size()); i++)rmq.push_back(0);
	                                    ^
Main.java:34: error: class, interface, or enum expected
	for(int i=(int)(arr.size()); i<2*(int)(arr.size()); i++){
	^
Main.java:34: error: class, interface, or enum expected
	for(int i=(int)(arr.size()); i<2*(int)(arr.size()); i++){
	                             ^
Main.java:34: error: class, interface, or enum expected
	for(int i=(int)(arr.size()); i<2*(int)(arr.size()); i++){
	                                                    ^
Main.java:36: error: class, interface, or enum expected
	}
	^
Main.java:37: error: class, interface, or enum expected
	for(int i=(int)arr.size()-1; i>=1; i--){
	                             ^
Main.java:37: error: class, interface, or enum expected
	for(int i=(int)arr.size()-1; i>=1; i--){
	                                   ^
Main.java:40: error: class, interface, or enum expected
		}else{
		^
Main.java:42: error: class, interface, or enum expected
		}
		^
Main.java:49: error: class, interface, or enum expected
    memset(dp, 0, sizeof(dp));
    ^
Main.java:50: error: class, interface, or enum expected
    bool P[n][n];
    ^
Main.java:51: error: class, interface, or enum expected
    memset(P, false , sizeof(P));
    ^
Main.java:52: error: class, interface, or enum expected
    for (int i= 0; i< n; i++)
    ^
Main.java:52: error: class, interface, or enum expected
    for (int i= 0; i< n; i++)
                   ^
Main.java:52: error: class, interface, or enum expected
    for (int i= 0; i< n; i++)
                         ^
Main.java:55: error: class, interface, or enum expected
    for (int i=0; i<n-1; i++){
    ^
Main.java:55: error: class, interface, or enum expected
    for (int i=0; i<n-1; i++){
                  ^
Main.java:55: error: class, interface, or enum expected
    for (int i=0; i<n-1; i++){
                         ^
Main.java:58: error: class, interface, or enum expected
            dp[i][i+1] = 1 ;
            ^
Main.java:59: error: class, interface, or enum expected
        }
        ^
Main.java:61: error: class, interface, or enum expected
    for (int gap=2 ; gap<n; gap++){
                     ^
Main.java:61: error: class, interface, or enum expected
    for (int gap=2 ; gap<n; gap++){
                            ^
Main.java:62: error: class, interface, or enum expected
        for (int i=0; i<n-gap; i++){
                      ^
Main.java:62: error: class, interface, or enum expected
        for (int i=0; i<n-gap; i++){
                               ^
Main.java:67: error: class, interface, or enum expected
            if (str[i] == str[j] && P[i+1][j-1] )
            ^
Main.java:73: error: class, interface, or enum expected
            if (P[i][j] == true)
            ^
Main.java:75: error: class, interface, or enum expected
            else
            ^
Main.java:77: error: class, interface, or enum expected
        }
        ^
Main.java:82: error: class, interface, or enum expected
}
^
Main.java:86: error: class, interface, or enum expected
	rmq.clear();
	^
Main.java:87: error: class, interface, or enum expected
	int n,m;
	^
Main.java:88: error: class, interface, or enum expected
	scanf("%d %d", &n, &m);
	^
Main.java:89: error: class, interface, or enum expected
	map<string, int> id;
	^
Main.java:90: error: class, interface, or enum expected
	forn(i, n){
	^
Main.java:92: error: class, interface, or enum expected
		scanf("%s", tmp);
		^
Main.java:93: error: class, interface, or enum expected
		int nu=CountPS(tmp, sizeof(tmp));
		^
Main.java:94: error: class, interface, or enum expected
		arr.pb(nu+sizeof(tmp));
		^
Main.java:95: error: class, interface, or enum expected
		id[tmp]=i;
		^
Main.java:96: error: class, interface, or enum expected
	}
	^
Main.java:98: error: class, interface, or enum expected
	while(p2<(int)arr.size())p2*=2;
	^
Main.java:99: error: class, interface, or enum expected
	while(p2>(int)arr.size())arr.pb(0);
	^
Main.java:100: error: class, interface, or enum expected
	build();
	^
Main.java:101: error: class, interface, or enum expected
	while(m--){
	^
Main.java:103: error: class, interface, or enum expected
		scanf("%s %s", s1, s2);
		^
Main.java:104: error: class, interface, or enum expected
		int l=id[s1];
		^
Main.java:105: error: class, interface, or enum expected
		int r=id[s2];
		^
Main.java:106: error: class, interface, or enum expected
		r++;
		^
Main.java:107: error: class, interface, or enum expected
		cout<<res(1, 0, (int)arr.size(), l, r)+1<<endl;
		^
Main.java:108: error: class, interface, or enum expected
	}
	^
Main.java:114: error: class, interface, or enum expected
	scanf("%d", &T);
	^
Main.java:115: error: class, interface, or enum expected
	while(T--)solve();
	^
Main.java:116: error: class, interface, or enum expected
}
^
77 errors
stdout
Standard output is empty