标签:
#include <map>
#include <set>
#include <ctime>
#include <stack>
#include <cmath>
#include <queue>
#include <bitset>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <fstream>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <iostream>
#include <algorithm>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
#define maxn 8000+10
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define clr(x,y) memset(x,y,sizeof(x))
#define rep(i,n) for(int i=0;i<(n);i++)
#define repf(i,a,b) for(int i=(a);i<=(b);i++)
#define pii pair<int,int>
#define mp make_pair
#define FI first
#define SE second
#define IT iterator
#define PB push_back
#define Times 10
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const double eps = 1e-10;
const double pi = acos(-1.0);
const ll mod = 1e9+7;
const int inf = 0x3f3f3f3f;
inline void RI(int& x)
{
x=0;
char c=getchar();
while(!((c>=‘0‘&&c<=‘9‘)||c==‘-‘))c=getchar();
bool flag=1;
if(c==‘-‘)
{
flag=0;
c=getchar();
}
while(c<=‘9‘&&c>=‘0‘)
{
x=x*10+c-‘0‘;
c=getchar();
}
if(!flag)x=-x;
}
//--------------------------------------------------
int col[maxn<<2];
int vis[maxn];
int anw[maxn];
void build(int l,int r,int rt){
col[rt]=-1;
if(l==r){
return ;
}
int m=(l+r)>>1;
build(lson);
build(rson);
}
void pushdown(int rt){
if(col[rt]!=-1){
col[rt<<1]=col[rt<<1|1]=col[rt];
col[rt]=-1;
}
}
void update(int l,int r,int rt,int L,int R,int p){
if(L<=l&&r<=R){
col[rt]=p;
return;
}
pushdown(rt);
int m=(l+r)>>1;
if(L<=m)update(lson,L,R,p);
if(R>m) update(rson,L,R,p);
}
void query(int l,int r,int rt){
if(col[rt]!=-1){
for(int i=l;i<=r;i++)
anw[i]=col[rt];
return ;
}
if(l==r){
anw[l]=-1;
return ;
}
pushdown(rt);
int m=(l+r)>>1;
query(lson);
query(rson);
}
int main(){
//freopen("d:\\acm\\in.in","r",stdin);
int n;
while(~scanf("%d",&n)){
build(1,8000,1);
while(n--){
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
a++;
update(1,8000,1,a,b,c);
}
query(1,8000,1);
clr(vis,0);
if(anw[1]!=-1)vis[anw[1]]++;
for(int i=2;i<=8000;i++)
if(anw[i]!=-1&&anw[i]!=anw[i-1])
vis[anw[i]]++;
for(int i=0;i<=8000;i++)
if(vis[i])
printf("%d %d\n",i,vis[i]);
puts("");
}
return 0;
}
#include <map>
#include <set>
#include <ctime>
#include <stack>
#include <cmath>
#include <queue>
#include <bitset>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <fstream>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <iostream>
#include <algorithm>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
#define maxn 50000+10
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define clr(x,y) memset(x,y,sizeof(x))
#define rep(i,n) for(int i=0;i<(n);i++)
#define repf(i,a,b) for(int i=(a);i<=(b);i++)
#define pii pair<int,int>
#define mp make_pair
#define FI first
#define SE second
#define IT iterator
#define PB push_back
#define Times 10
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const double eps = 1e-10;
const double pi = acos(-1.0);
const ll mod = 1e9+7;
const int inf = 0x3f3f3f3f;
inline void RI(int& x)
{
x=0;
char c=getchar();
while(!((c>=‘0‘&&c<=‘9‘)||c==‘-‘))c=getchar();
bool flag=1;
if(c==‘-‘)
{
flag=0;
c=getchar();
}
while(c<=‘9‘&&c>=‘0‘)
{
x=x*10+c-‘0‘;
c=getchar();
}
if(!flag)x=-x;
}
//--------------------------------------------------
int minn[maxn<<2];
int maxx[maxn<<2];
void pushup(int rt){
minn[rt]=min(minn[rt<<1],minn[rt<<1|1]);
maxx[rt]=max(maxx[rt<<1],maxx[rt<<1|1]);
}
void build(int l,int r,int rt){
if(l==r){
scanf("%d",&minn[rt]);
maxx[rt]=minn[rt];
return;
}
int m=(l+r)>>1;
build(lson);
build(rson);
pushup(rt);
}
int query(int l,int r,int rt,int L,int R){
if(L<=l&&r<=R){
return minn[rt];
}
int ans=inf;
int m=(l+r)>>1;
if(L<=m)ans=min(ans,query(lson,L,R));
if(R>m) ans=min(ans,query(rson,L,R));
return ans;
}
int query1(int l,int r,int rt,int L,int R){
if(L<=l&&r<=R){
return maxx[rt];
}
int ans=0;
int m=(l+r)>>1;
if(L<=m)ans=max(ans,query1(lson,L,R));
if(R>m) ans=max(ans,query1(rson,L,R));
return ans;
}
int main(){
//freopen("d:\\acm\\in.in","r",stdin);
int n,q;
while(~scanf("%d %d",&n,&q)){
build(1,n,1);
while(q--){
int a,b;
scanf("%d %d",&a,&b);
printf("%d\n",query1(1,n,1,a,b)-query(1,n,1,a,b));
}
}
return 0;
}
#include <map>
#include <set>
#include <ctime>
#include <stack>
#include <cmath>
#include <queue>
#include <bitset>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <fstream>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <iostream>
#include <algorithm>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
#define maxn 100000+10
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define clr(x,y) memset(x,y,sizeof(x))
#define rep(i,n) for(int i=0;i<(n);i++)
#define repf(i,a,b) for(int i=(a);i<=(b);i++)
#define pii pair<int,int>
#define mp make_pair
#define FI first
#define SE second
#define IT iterator
#define PB push_back
#define Times 10
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const double eps = 1e-10;
const double pi = acos(-1.0);
const ll mod = 1e9+7;
const int inf = 0x3f3f3f3f;
inline void RI(int& x)
{
x=0;
char c=getchar();
while(!((c>=‘0‘&&c<=‘9‘)||c==‘-‘))c=getchar();
bool flag=1;
if(c==‘-‘)
{
flag=0;
c=getchar();
}
while(c<=‘9‘&&c>=‘0‘)
{
x=x*10+c-‘0‘;
c=getchar();
}
if(!flag)x=-x;
}
//--------------------------------------------------
int col[maxn<<2];
int ans;
bool vis[maxn];
void pushdown(int rt){
if(col[rt]){
col[rt<<1]=col[rt<<1|1]=col[rt];
col[rt]=0;
}
}
void update(int l,int r,int rt,int L,int R,int p){
if(L<=l&&r<=R){
col[rt]=p;
return;
}
pushdown(rt);
int m=(l+r)>>1;
if(L<=m)update(lson,L,R,p);
if(R>m) update(rson,L,R,p);
}
void query(int l,int r,int rt,int L,int R){
if(col[rt]){
if(!vis[col[rt]]){
ans++;
vis[col[rt]]=true;
}
return;
}
if(l==r)return;
int m=(l+r)>>1;
if(L<=m)query(lson,L,R);
if(R>m) query(rson,L,R);
}
int main(){
//freopen("d:\\acm\\in.in","r",stdin);
int n,t,p;
while(~scanf("%d %d %d",&n,&t,&p)){
col[1]=1;
while(p--){
char op[5];
int a,b,c;
scanf("%s %d %d",op,&a,&b);
if(a>b)swap(a,b);
if(op[0]==‘C‘){
scanf("%d",&c);
update(1,n,1,a,b,c);
}
else {
ans=0;
for(int i=1;i<=t;i++)
vis[i]=false;
query(1,n,1,a,b);
printf("%d\n",ans);
}
}
}
return 0;
}
#include <map>
#include <set>
#include <ctime>
#include <stack>
#include <cmath>
#include <queue>
#include <bitset>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <fstream>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <iostream>
#include <algorithm>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
#define maxn 100000+10
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define clr(x,y) memset(x,y,sizeof(x))
#define rep(i,n) for(int i=0;i<(n);i++)
#define repf(i,a,b) for(int i=(a);i<=(b);i++)
#define pii pair<int,int>
#define mp make_pair
#define FI first
#define SE second
#define IT iterator
#define PB push_back
#define Times 10
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const double eps = 1e-10;
const double pi = acos(-1.0);
const ll mod = 1e9+7;
const int inf = 0x3f3f3f3f;
inline void RI(int& x)
{
x=0;
char c=getchar();
while(!((c>=‘0‘&&c<=‘9‘)||c==‘-‘))c=getchar();
bool flag=1;
if(c==‘-‘)
{
flag=0;
c=getchar();
}
while(c<=‘9‘&&c>=‘0‘)
{
x=x*10+c-‘0‘;
c=getchar();
}
if(!flag)x=-x;
}
//--------------------------------------------------
ll sum[maxn<<2];
void pushup(int rt){
sum[rt]=sum[rt<<1]+sum[rt<<1|1];
}
void build(int l,int r,int rt){
if(l==r){
scanf("%lld",&sum[rt]);
return;
}
int m=(l+r)>>1;
build(lson);
build(rson);
pushup(rt);
}
void update(int l,int r,int rt,int L,int R){
if(sum[rt]==(r-l+1)){
return;
}
if(l==r){
sum[rt]=(int)sqrt(sum[rt]*1.0);
return;
}
int m=(l+r)>>1;
if(L<=m)update(lson,L,R);
if(R>m)update(rson,L,R);
pushup(rt);
}
ll query(int l,int r,int rt,int L,int R){
if(L<=l&&r<=R){
return sum[rt];
}
int m=(l+r)>>1;
ll ans=0;
if(L<=m)ans+=query(lson,L,R);
if(R>m) ans+=query(rson,L,R);
return ans;
}
int main(){
//freopen("d:\\acm\\in.in","r",stdin);
int n,cas=1;
while(~scanf("%d",&n)){
printf("Case #%d:\n",cas++);
build(1,n,1);
int q;
scanf("%d",&q);
while(q--){
int t,a,b;
scanf("%d %d %d",&t,&a,&b);
if(a>b)swap(a,b);
if(t==1)printf("%lld\n",query(1,n,1,a,b));
else update(1,n,1,a,b);
}
puts("");
}
return 0;
}
#include <map>
#include <set>
#include <ctime>
#include <stack>
#include <cmath>
#include <queue>
#include <bitset>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <fstream>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <iostream>
#include <algorithm>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
#define maxn 131070+10
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define clr(x,y) memset(x,y,sizeof(x))
#define rep(i,n) for(int i=0;i<(n);i++)
#define repf(i,a,b) for(int i=(a);i<=(b);i++)
#define pii pair<int,int>
#define mp make_pair
#define FI first
#define SE second
#define IT iterator
#define PB push_back
#define Times 10
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const double eps = 1e-10;
const double pi = acos(-1.0);
const ll mod = 1e9+7;
const int inf = 0x3f3f3f3f;
inline void RI(int& x)
{
x=0;
char c=getchar();
while(!((c>=‘0‘&&c<=‘9‘)||c==‘-‘))c=getchar();
bool flag=1;
if(c==‘-‘)
{
flag=0;
c=getchar();
}
while(c<=‘9‘&&c>=‘0‘)
{
x=x*10+c-‘0‘;
c=getchar();
}
if(!flag)x=-x;
}
//--------------------------------------------------
const int len = 131070;
int Xor[maxn<<2];
int col[maxn<<2];
int anw[maxn];
void cal(int rt){
if(col[rt]!=-1)col[rt]^=1;
else Xor[rt]^=1;
}
void pushdown(int rt){
if(col[rt]!=-1){
col[rt<<1]=col[rt<<1|1]=col[rt];
Xor[rt]=0;
col[rt]=-1;
}
else if(Xor[rt]){
cal(rt<<1);
cal(rt<<1|1);
Xor[rt]=0;
}
}
void update(int l,int r,int rt,int L,int R,int p){
if(L<=l&&r<=R){
col[rt]=p;
return;
}
pushdown(rt);
int m=(l+r)>>1;
if(L<=m)update(lson,L,R,p);
if(R>m) update(rson,L,R,p);
}
void updata(int l,int r,int rt,int L,int R){
if(L<=l&&r<=R){
cal(rt);
return;
}
pushdown(rt);
int m=(l+r)>>1;
if(L<=m)updata(lson,L,R);
if(R>m) updata(rson,L,R);
}
void query(int l,int r,int rt){
if(col[rt]!=-1){
if(col[rt]){
for(int i=l;i<=r;i++)
anw[i]=col[rt];
}
return;
}
pushdown(rt);
int m=(l+r)>>1;
query(lson);
query(rson);
}
int main(){
//freopen("d:\\acm\\in.in","r",stdin);
int a,b;
char c,d,op;
col[1]=Xor[1]=0;
while(~scanf("%c %c%d,%d%c\n",&op,&c,&a,&b,&d)){
a<<=1;if(c==‘(‘)a++;
b<<=1;if(d==‘)‘)b--;
if(op==‘U‘)update(0,len,1,a,b,1);
else if(op==‘I‘){
if(a!=0)update(0,len,1,0,a-1,0);
if(b!=len)update(0,len,1,b+1,len,0);
}
else if(op==‘D‘)update(0,len,1,a,b,0);
else if(op==‘C‘){
if(a!=0)update(0,len,1,0,a-1,0);
if(b!=len)update(0,len,1,b+1,len,0);
updata(0,len,1,a,b);
}
else updata(0,len,1,a,b);
/*query(0,len,1);
for(int i=0;i<=10;i++)
cout<<anw[i]<<" ";
cout<<endl;*/
}
query(0,len,1);
queue<int>que;
if(anw[0])que.push(0);
for(int i=1;i<=len;i++)
if(anw[i]&&!anw[i-1])que.push(i);
else if(anw[i-1]&&!anw[i])que.push(i-1);
if(anw[len])que.push(len);
if(que.empty())puts("empty set");
else {
int cnt=0;
while(!que.empty()){
int a=que.front();
que.pop();
int b=que.front();
que.pop();
if(cnt)putchar(‘ ‘);
cnt=1;
if(a&1)printf("(%d,",a/2);
else printf("[%d,",a/2);
if(b&1)printf("%d)",(b+1)/2);
else printf("%d]",b/2);
}
putchar(‘\n‘);
}
return 0;
}
#include <map>
#include <set>
#include <ctime>
#include <stack>
#include <cmath>
#include <queue>
#include <bitset>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <fstream>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <iostream>
#include <algorithm>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
#define maxn 16000+10
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define clr(x,y) memset(x,y,sizeof(x))
#define rep(i,n) for(int i=0;i<(n);i++)
#define repf(i,a,b) for(int i=(a);i<=(b);i++)
#define pii pair<int,int>
#define mp make_pair
#define FI first
#define SE second
#define IT iterator
#define PB push_back
#define Times 10
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const double eps = 1e-10;
const double pi = acos(-1.0);
const ll mod = 1e9+7;
const int inf = 0x3f3f3f3f;
inline void RI(int& x)
{
x=0;
char c=getchar();
while(!((c>=‘0‘&&c<=‘9‘)||c==‘-‘))c=getchar();
bool flag=1;
if(c==‘-‘)
{
flag=0;
c=getchar();
}
while(c<=‘9‘&&c>=‘0‘)
{
x=x*10+c-‘0‘;
c=getchar();
}
if(!flag)x=-x;
}
//--------------------------------------------------
bool vis[8010][8010];
const int len = 16000;
struct edge{
int l,r;
int x;
friend bool operator < (const edge& A,const edge& B){
return A.x<B.x;
}
}dat[maxn];
int col[maxn<<2];
void build(int l,int r,int rt){
col[rt]=0;
if(l==r){
return;
}
int m=(l+r)>>1;
build(lson);
build(rson);
}
void query(int l,int r,int rt,int L,int R,int x){
if(col[rt]){
vis[x][col[rt]]=vis[col[rt]][x]=true;
return;
}
if(l==r)return;
int m=(l+r)>>1;
if(L<=m)query(lson,L,R,x);
if(R>m)query(rson,L,R,x);
}
void pushdown(int rt){
if(col[rt]){
col[rt<<1]=col[rt<<1|1]=col[rt];
col[rt]=0;
}
}
void update(int l,int r,int rt,int L,int R,int x){
if(L<=l&&r<=R){
col[rt]=x;
return;
}
pushdown(rt);
int m=(l+r)>>1;
if(L<=m)update(lson,L,R,x);
if(R>m)update(rson,L,R,x);
}
int main(){
//freopen("d:\\acm\\in.in","r",stdin);
int t;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d %d %d",&dat[i].l,&dat[i].r,&dat[i].x);
sort(dat,dat+n);
build(0,len,1);
clr(vis,false);
for(int i=0;i<n;i++){
query(0,len,1,dat[i].l<<1,dat[i].r<<1,i+1);
update(0,len,1,dat[i].l<<1,dat[i].r<<1,i+1);
}
/*for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++)
cout<<vis[i][j]<<" ";
cout<<endl;
}*/
int ans=0;
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
if(vis[i][j]){
for(int k=j+1;k<=n;k++)
if(vis[j][k]&&vis[i][k])
ans++;
}
cout<<ans<<endl;
}
return 0;
}
#include <map>
#include <set>
#include <ctime>
#include <stack>
#include <cmath>
#include <queue>
#include <bitset>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <fstream>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <iostream>
#include <algorithm>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
#define maxn 10000+10
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define clr(x,y) memset(x,y,sizeof(x))
#define rep(i,n) for(int i=0;i<(n);i++)
#define repf(i,a,b) for(int i=(a);i<=(b);i++)
#define pii pair<int,int>
#define mp make_pair
#define FI first
#define SE second
#define IT iterator
#define PB push_back
#define Times 10
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const double eps = 1e-10;
const double pi = acos(-1.0);
const ll mod = 1e9+7;
const int inf = 0x3f3f3f3f;
inline void RI(int& x)
{
x=0;
char c=getchar();
while(!((c>=‘0‘&&c<=‘9‘)||c==‘-‘))c=getchar();
bool flag=1;
if(c==‘-‘)
{
flag=0;
c=getchar();
}
while(c<=‘9‘&&c>=‘0‘)
{
x=x*10+c-‘0‘;
c=getchar();
}
if(!flag)x=-x;
}
//--------------------------------------------------
int col[maxn<<2];
double X[maxn<<2],Y[maxn<<2];
int dep[maxn];
void pushup(int rt){
X[rt]=X[rt<<1]+X[rt<<1|1];
Y[rt]=Y[rt<<1]+Y[rt<<1|1];
}
void build(int l,int r,int rt){
col[rt]=0;
if(l==r){
X[rt]=0;
scanf("%lf",&Y[rt]);
return ;
}
int m=(l+r)>>1;
build(lson);
build(rson);
pushup(rt);
}
void cal(double& x,double& y,int p){
double ang=p*pi/180.0;
double tx=x*cos(ang)-y*sin(ang);
double ty=x*sin(ang)+y*cos(ang);
x=tx;
y=ty;
}
void pushdown(int rt){
if(col[rt]){
col[rt<<1]+=col[rt];
col[rt<<1|1]+=col[rt];
cal(X[rt<<1],Y[rt<<1],col[rt]);
cal(X[rt<<1|1],Y[rt<<1|1],col[rt]);
col[rt]=0;
}
}
void update(int l,int r,int rt,int L,int R,int p){
if(L<=l&&r<=R){
cal(X[rt],Y[rt],p);
col[rt]+=p;
return;
}
pushdown(rt);
int m=(l+r)>>1;
if(L<=m)update(lson,L,R,p);
if(R>m) update(rson,L,R,p);
pushup(rt);
}
int main(){
//freopen("d:\\acm\\in.in","r",stdin);
int n,m,cnt=0;
while(~scanf("%d %d",&n,&m)){
if(cnt)putchar(‘\n‘);
cnt=1;
build(1,n,1);
for(int i=1;i<=n;i++)
dep[i]=180;
while(m--){
int p,h;
scanf("%d %d",&p,&h);
update(1,n,1,p+1,n,h-dep[p]);
dep[p]=h;
printf("%.2lf %.2lf\n",X[1],Y[1]);
}
}
return 0;
}
标签:
原文地址:http://blog.csdn.net/shengtao96/article/details/51871560