鹿艺昂 @ 2019-10-02 11:08:46
using namesapce std; int main() { int a,b,c; cin>>a>>b; c=a+b; cout<<c; return 0;//wonderful }
by lygmh @ 2019-10-02 11:20:23
https://www.luogu.org/discuss/show/148950
by _gifbmp @ 2019-10-02 11:20:27
这题最简单了
by Suphx @ 2019-10-02 11:21:40
@鹿艺昂 这题也不错勒
by lygmh @ 2019-10-02 11:43:01
@空与白之灵 推荐这个吧
by 菜鸟k @ 2019-10-02 13:58:35
@鹿艺昂 https://www.luogu.org/discuss/show/148950
by d3ac @ 2019-10-03 19:48:33
#pragma GCC optimize(2,3,"Ofast","inline","-fgcse")
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#define maxn 4000
#define inf 2000000
using namespace std;
int n,m,d,need[maxn],left,right;
long long love[maxn],hate[maxn],lastans=-1e17,lasthate=1e17;
bool book[maxn];
vector<int> v[maxn];
inline int read(){
register int x=0,f=1; register char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar();}
while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
return x*f;
}
int main()
{
n=read(); m=read(); d=read();
for(int i=1;i<=d;i++) need[i]=read(),book[need[i]]=true;//输入喜欢的数字并且标记
for(int i=1,temp,cnt,hated;i<=n;i++){
temp=read(); cnt=read();
love[i]=love[i-1]+temp;//维护魔力值的前缀和
hated=0;
for(int j=1;j<=cnt;j++){
temp=read();//这个是数字
if(book[temp]) v[temp].push_back(i);//需要去重
else hated++;
}
hate[i]=hate[i-1]+hated;//维护讨厌的数字的前缀和
}
for(int i=1;i<=d;i++) {
if(v[need[i]].size()==0) printf("-1"),exit(0);
v[need[i]].push_back(inf);
}
for(int i=1;i<=n;i++){//枚举区间的起点
int r=0;
for(int j=1;j<=d;j++){//枚举每一个数字,保证被选中
r=max(r,v[need[j]].at(lower_bound(v[need[j]].begin(),v[need[j]].end(),i)-v[need[j]].begin()));
}
if(r==inf) break;//后面的区间一定覆盖不完了
while(hate[r]==hate[r+1] && love[r]<love[r+1] && r!=n) r++;//尽量使r更大
long long nowans=love[r]-love[i-1];
long long nowhate=hate[r]-hate[i-1];
if(lasthate<nowhate) continue;
if(lasthate!=nowhate){
lasthate=nowhate;
lastans=nowans,left=i,right=r;
}
else if(lastans<nowans) lastans=nowans,left=i,right=r;
}
lastans==-1e17? printf("-1\n"):printf("%d %d\n",left,right);
return 0;
}
by bunH2O @ 2019-10-05 20:48:12
@鹿艺昂 这个更简单
by d3ac @ 2019-10-06 15:33:19
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<stack>
#define maxn 1000000
using namespace std;
int read(){
register int x=0,f=1; register char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar();}
while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
return x*f;
}
int n,k,top,Time,head[maxn],fa[maxn],low[maxn],dfn[maxn];
bool book[maxn],instack[maxn];
stack<int> st;
struct datanode{
int min,max;
}data[maxn];
struct ansnode{
int u,v;
}ans[maxn];
struct node{
int to,next;
}edge[maxn];
void add(int u,int v){
edge[++k]=(node){v,head[u]}; head[u]=k;
edge[++k]=(node){u,head[v]}; head[v]=k;
}
int find(int x){
while(x!=fa[x]) x=fa[x]=fa[fa[x]];
return x;
}
void merge(int x,int y) {fa[find(x)]=find(y);}
bool cmp(ansnode a,ansnode b) {return a.u==b.u?a.v<b.v:a.u<b.u;}
void tarjan(int u,int fa){
dfn[u]=low[u]=++Time;
instack[u]=true; st.push(u);
for(int i=head[u];i;i=edge[i].next){
if(edge[i].to==fa) continue;
if(!dfn[edge[i].to]) tarjan(edge[i].to,u),low[u]=min(low[u],low[edge[i].to]);
else if(instack[edge[i].to]) low[u]=min(low[u],low[edge[i].to]);
}
if(dfn[u]==low[u]){
if(st.top()!=u) printf("-1\n"),exit(0);
instack[u]=false;
st.pop();
}
}
int main()
{
n=read();
for(int i=1;i<=n;i++) fa[i]=i;
for(int i=1;i<=n;i++){
data[i].min=read(); data[i].max=read();
if(data[i].min==data[i].max) {
merge(i,data[i].min);//随便先连接
add(i,data[i].min); book[i]=true;
ans[++top]=(ansnode){i,data[i].min};
}else{
merge(i,data[i].min); merge(i,data[i].max);
add(i,data[i].min); add(i,data[i].max);
ans[++top]=(ansnode){i,data[i].min};
ans[++top]=(ansnode){i,data[i].max};
}
}
for(int i=1;i<=n;i++) if(!dfn[i]) tarjan(i,i);
for(int i=1;i<=n;i++){
if(book[i]) continue;
for(int j=1;j<=n;j++){
if(i==j || book[j] || find(i)==find(j)) continue;
if(!(data[i].min<=j && j<=data[i].max && data[j].min<=i && i<=data[j].max)) continue;
ans[++top]=(ansnode){i,j};
merge(i,j);
}
}
int base=find(1);
for(int i=1;i<=n;i++) if(find(i)!=base) printf("-1\n"),exit(0);
for(int i=1;i<=top;i++) if(ans[i].v<ans[i].u) swap(ans[i].u,ans[i].v);
sort(ans+1,ans+1+top,cmp);
for(int i=1;i<=top;i++) {
if(ans[i].u==ans[i-1].u && ans[i].v==ans[i-1].v) continue;
printf("%d %d\n",ans[i].u,ans[i].v);
}
return 0;
}
by Modest_ @ 2019-10-06 17:28:54
using namespace std; /*namespace fastIO {
#define OUT_SIZE 100000
#define ll long long
bool IOerror=0;
inline char nc()
{
static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;
if(p1==pend)
{
p1=buf;
pend=buf+fread(buf,1,BUF_SIZE,stdin);
if(pend==p1){IOerror=1;return -1;}
}
return *p1++;
}
inline bool blank(char ch){return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';}
inline void read(int &x)
{
bool sign=0;
char ch=nc();
x=0;
for(;blank(ch);ch=nc());
if(IOerror)return;
if(ch=='-')sign=1,ch=nc();
for(;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0';
if(sign)x=-x;
}
inline void read(ll &x)
{
bool sign=0;
char ch=nc();
x=0;
for(;blank(ch);ch=nc());
if(IOerror)return;
if(ch=='-')sign=1,ch=nc();
for(;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0';
if(sign)x=-x;
}
char ss[1000000*15],tt[20];
int ssl,ttl;
inline int Flush()
{
fwrite(ss+1,sizeof(char),ssl,stdout);
ssl=0;
return 0;
}
inline int print(int x)
{
if(!x)ss[++ssl]='0';
if(x<0)ss[++ssl]='-',x=-x;
for(ttl=0;x;x/=10)tt[++ttl]=char(x%10+'0');
for(;ttl;ttl--)ss[++ssl]=tt[ttl];
return ss[++ssl]='\n';
}
inline int print(ll x)
{
if(!x)ss[++ssl]='0';
if(x<0)ss[++ssl]='-',x=-x;
for(ttl=0;x;x/=10)tt[++ttl]=char(x%10+'0');
for(;ttl;ttl--)ss[++ssl]=tt[ttl];
return ss[++ssl]='\n';
}
#undef OUT_SIZE
#undef BUF_SIZE
}; using namespace fastIO;*/
const int maxn=301010; const int inf=0x7f7f7f7f; int n,m,a[maxn],book[maxn],b[maxn];
int main() { //read(n);read(m); scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { //read(m); scanf("%d",&a[i]); } while(m--) { int l,r,c; //read(l);read(r);read(c); scanf("%d%d%d",&l,&r,&c); for(int i=l;i<=r;i++) { b[i]=a[i]; } sort(b+l,b+r+1); b[r+1]=inf; int tot=0; int st=b[l]; for(int i=l+1;i<=r+1;i++) { if(b[i]>b[i-1]+1) { if(b[i-1]-st+2==c) { tot++; } st=b[i]; } } printf("%d\n",tot); } return 0; }
by L______ @ 2019-10-06 17:28:58
using namespace std; inline ll read(){ ll x=0,f=1;char ch=getchar(); while(ch<'0' || ch>'9'){if(ch=='-') f=-1;ch=getchar();} while(ch>='0' && ch<='9'){x=x10+ch-'0';ch=getchar();} return xf; }
int n,m,a[N]; bool book[N];
int main(){ n=read(),m=read(); for(int i=1;i<=n;i++){ a[i]=read(); } while(m--){ int l=read(),r=read(),x=read(); int maxx=-inf,minn=inf; memset(book,0,sizeof(book)); for(int i=l;i<=r;i++){ maxx=max(maxx,a[i]); minn=min(minn,a[i]); book[a[i]]=1; } int cnt=0; for(int i=max(0,minn-x);i<=maxx;i++){ int j=i+x; if(book[i]==1 || book[j]==1) continue; if(book[i]==1) continue; if(book[j]==1) continue; int flag=0; for(int k=i+10;k<=j-1;k++){ if(book[k]==1){ flag=1; break; } }
printf("%d\n",cnt); if(flag!=1) cnt++;
return 0; }
}
}
}