setpresetion @ 2024-01-29 14:21:26
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,i,j,k,maxn=0,f[1001000],ok[1000100];
struct node{
int s,t,w;
}a[1001000];
bool valid(int x){
memset(f,0,sizeof(f));
for(i=1;i<=x;++i){
f[a[i].s]+=a[i].w;
f[a[i].t+1]-=a[i].w;
}
j=0;
for(i=1;i<=n;++i){
j+=f[i];
if(j>ok[i])return false;
}
return true;
}
int main(){
memset(f,0,sizeof(f));
scanf("%d%d",&n,&m);
for(i=1;i<=n;++i)scanf("%d",&ok[i]);
for(i=1;i<=m;++i)scanf("%d%d%d",&a[i].w,&a[i].s,&a[i].t);
if(valid(m)){printf("0\n");return 0;}
int l=1,r=m;
while(l<r){
int mid=(l+r)/2;
if(valid(mid)) l=mid+1;
else r=mid;
}
printf("-1\n%d\n",l);
return 0;
}
结果是20分: | wa | tle |
---|---|---|
re | ac | |
wa | wa | |
tle | tle | |
ac | wa |
by RaymondOccam @ 2024-02-17 15:47:10
@rickyxue 用printf干嘛?
把sync关了,跑cin和cout它不香吗
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// PS:不需要附加其他头文件
不满意?
火车头直接起飞
#include <iostream>
#pragma GCC optimize("Ofast", "inline", "-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
// PS:有些oj的测评机特别友(dú)善(liú),打比赛最好别用火车头优化了
by test_daily @ 2024-02-17 18:33:35
你干嘛要高精度,你直接long long就可以了
by qby1166 @ 2024-02-18 17:45:34
nb
by liuguanyu @ 2024-02-19 15:42:49
@rickyxue 6
by quxiangyu @ 2024-02-19 21:24:56
高精度是这样的:
#include<bits/stdc++.h>
using namespace std;
const int N = 1005;
struct bign
{
int len,s[N];
bign() { memset(s,0,sizeof(s)); len=1; }
bign(int num) { *this=num; }
bign(char *num) { *this=num; }
bign operator =(int num)
{
char c[N];
sprintf(c,"%d",num);
*this=c;
return *this;
}
bign operator =(const char *num)
{
len=strlen(num);
for (int i=0;i<len;i++) s[i]=num[len-1-i]-'0';
return *this;
}
string str()
{
string res="";
for (int i=0;i<len;i++) res=(char)(s[i]+'0')+res;
return res;
}
void clean()
{
while (len>1&&!s[len-1]) len--;
}
bign operator +(const bign &b)
{
bign c;
c.len=0;
for (int i=0,g=0;g||i<len||i<b.len;i++)
{
int x=g;
if (i<len) x+=s[i];
if (i<b.len) x+=b.s[i];
c.s[c.len++]=x%10;
g=x/10;
}
return c;
}
bign operator -(const bign &b)
{
bign c;
c.len=0;
int x;
for (int i=0,g=0;i<len;i++)
{
x=s[i]-g;
if (i<b.len) x-=b.s[i];
if (x>=0) g=0;
else{
x+=10;
g=1;
};
c.s[c.len++]=x;
}
c.clean();
return c;
}
bign operator *(const bign &b)
{
bign c;
c.len=len+b.len;
for (int i=0;i<len;i++) for (int j=0;j<b.len;j++) c.s[i+j]+=s[i]*b.s[j];
for (int i=0;i<c.len-1;i++) { c.s[i+1]+=c.s[i]/10; c.s[i]%=10; }
c.clean();
return c;
}
bool operator <(const bign &b)
{
if (len!=b.len) return len<b.len;
for (int i=len-1;i>=0;i--)
if (s[i]!=b.s[i]) return s[i]<b.s[i];
return false;
}
bign operator +=(const bign &b)
{
*this=*this+b;
return *this;
}
bign operator -=(const bign &b)
{
*this=*this-b;
return *this;
}
};
istream& operator >>(istream &in,bign &x)
{
string s;
in>>s;
x=s.c_str();
return in;
}
ostream& operator <<(ostream &out,bign &x)
{
out<<x.str();
return out;
}
int main(){
bign a,b,c;
ios::sync_with_stdio(false);
cin>>a>>b;
// cout<<a<<endl;
// cout<<b<<endl;
c=a+b;
cout<<c<<endl;
return 0;
}
by quxiangyu @ 2024-02-19 21:27:24
但是这题不能过
by RaymondOccam @ 2024-02-21 20:54:13
@xiaoshumiao 是你不懂吧
by xiaoshumiao @ 2024-02-21 21:36:39
@mini123 你有本事用 int 过一遍试试
by zhengkaiyang @ 2024-02-25 11:02:35
6
by RaymondOccam @ 2024-02-29 21:00:25
@xiaoshumiao
本来就不是int的问题好不好?