三角形
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define LL long long
using namespace std;
LL read(){
LL x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-') f=-1;
ch=getchar();
}
while(ch<='9'&&ch>='0'){
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
const int N=300007;
LL n,num,f[N],ans=0;
struct node{
LL a,b;
#define a(x) c[x].a
#define b(x) c[x].b
}c[N];
inline LL gcd(LL x,LL y){
if(y==0) return x;
else return gcd(y,x%y);
}
inline bool cmp(const node &x,const node &y){
if(x.a!=y.a) return x.a<y.a;
return x.b<y.b;
}
inline LL C(LL x,LL y){
if(x<y) return 0;
LL sum1=1,sum2=1;
for(register int i=x;i>=x-y+1;i--) sum1*=i;
for(register int i=1;i<=y;i++) sum2*=i;
return sum1/sum2;
}
int main(){
freopen("trokuti.in","r",stdin);
freopen("trokuti.out","w",stdout);
n=read();
LL x;
for(register int i=1;i<=n;i++){
a(i)=read();b(i)=read();x=read();
if(a(i)&&b(i)){
LL xx=abs(a(i)),yy=abs(b(i));
LL z=gcd(xx,yy);
a(i)=a(i)/z;
b(i)=b(i)/z;
}
}
sort(c+1,c+n+1,cmp);
for(register int i=1;i<=n;i++){
if(a(i)!=a(i-1)||b(i)!=b(i-1)){
num++;f[num]=1;
}
else f[num]++;
}
ans=C(n,3);
for(register int i=1;i<=num;i++)
ans=ans-C(f[i],2)*(n-f[i])-C(f[i],3);
printf("%lld",ans);
fclose(stdin);fclose(stdout);
return 0;
}
最长上升子序列
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define LL long long
using namespace std;
LL read(){
LL x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-') f=-1;
ch=getchar();
}
while(ch<='9'&&ch>='0'){
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
const int N=100007;
int n,st[N],top;
int main(){
freopen("manage.in","r",stdin);
freopen("manage.out","w",stdout);
n=read();
int x;
st[0]=-99999999;
for(int i=1;i<=n;i++){
x=read();
if(x>st[top]){
top++;
st[top]=x;
}
else{
int l=1,r=top,wz=0;
while(l<=r){
int mid=(l+r)/2;
if(st[mid]>x){
wz=mid;r=mid-1;
}else l=mid+1;
}
st[wz]=x;
}
}
printf("%d",top);
fclose(stdin);fclose(stdout);
return 0;
}