Bzoj2217 [POI2011] LIZ-Lollipop

Description

https://www.luogu.com.cn/problem/P3514

Solution

发现如果有一个序列的位置为 $1$,则小于等于这个序列的和都能被 $[1,i],[2,i]$ 表示出来。

只需要找到最左边的 $1$ 和右边的 $1$ 暴力跑一遍,然后对全局跑一遍就好了。感觉很充要啊!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define maxn 2000005
#define put() putchar('\n')
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
using namespace std;
Tp void read(T &x){
int f=1;x=0;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}
x*=f;
}
namespace Debug{
Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
}using namespace Debug;
#define fi first
#define se second
#define mk make_pair
const int mod=1e9+7;
int power(int x,int y=mod-2) {
int sum=1;
while (y) {
if (y&1) sum=sum*x%mod;
x=x*x%mod;y>>=1;
}
return sum;
}
int n,m;
int a[maxn],s[maxn];
pair<int,int>Ans[maxn];
void add(int l,int r) {
Ans[s[r]-s[l-1]]=mk(l,r);
}
signed main(void){
// freopen("1.in","r",stdin);
int i,j,x;char ch;
read(n);read(m);
for (cin>>ch,i=1;i<=n;i++) {
a[i]=(ch=='T'?2:1);
s[i]=s[i-1]+a[i];
ch=getchar();
}
for (i=1;i<=n;i++) if (a[i]==1) {
for (j=i;j<=n;j++) add(i,j);
for (j=i+1;j<=n;j++) add(i+1,j);
break;
}
for (i=n;i>=1;i--) if (a[i]==1) {
for (j=i;j>=1;j--) add(j,i);
for (j=1;j<i;j++) add(j,i-1);
break;
}
for (i=1;i<=n;i++) add(1,i),add(i,n);
while (m--) {
read(x);
if (Ans[x].fi) printf("%d %d\n",Ans[x].fi,Ans[x].se);
else puts("NIE");
}
return 0;
}