俾斯麦 @ 2019-10-17 15:02:03
蒟蒻代码写的丑,但这并不重要。
一组输出不一致的数据
10 9
719 583 321 556 741 430 50 28 326 804
A 1 10 321
M 1 10 101
A 1 10 337
A 1 10 596
M 1 10 511
A 1 10 142
A 1 10 99
A 1 10 88
M 1 10 609
正确答案是 8 8 5 10 10 10
本地的输出是 8 8 5 10 10 10
但在luoguIDE环境下 输出 9 9 5 13 13 13
话说,我居然会被这道题卡那么久。。。。救命!
下面是我的40分代码。
#include<bits/stdc++.h>
using namespace std ;
const int MAXN = 1000005 ;
#define ll long long
inline ll read(){
ll s=0 ; char g=getchar() ; while( g>'9'||g<'0' )g=getchar() ;
while( g>='0'&&g<='9' )s=s*10+g-'0',g=getchar() ; return s ;
}
inline int getc(){
char g=getchar() ; while(g!='A'&&g!='M')g=getchar() ;
return g=='A'?1:0 ;
}
ll N , M , a[ MAXN ] , b[ MAXN ] , block , L[ 1005 ] , R[ 1005 ] , ad[ 1005 ] , pos[ MAXN ] ;
int dx( int l , int r , int val ){
int mid , ans=r+1 , rr = r ;
while( l <= r ){
mid = (l+r)>>1 ;
if( b[mid] >= val )ans = mid , r = mid-1 ;
else l = mid+1 ;
}
return rr-ans+1 ;
}
void add( int l , int r , int val ){
int p = pos[l] , q = pos[r] ;
if( p==q ){
for( int i = l ; i <= r ; ++i )a[i] += val ;
for( int i = L[p] ; i <= R[p] ; ++i )b[i] = a[i]+ad[p] ; ad[p] = 0 ;
sort( b+L[p] , b+R[p] ) ; return ;
}
for( int i = l ; i <= R[p] ; ++i )a[i] += val ;//左边小区间
for( int i = L[p] ; i <= R[p] ; ++i )b[i] = a[i]+ad[p] ; ad[p] = 0 ;
sort( b+L[p] , b+R[p]+1 ) ;
for( int i = L[q] ; i <= r ; ++i )a[i] += val ;//右边小区间
for( int i = L[q] ; i <= R[q] ; ++i )b[i] = a[i]+ad[q] ; ad[q] = 0 ;
sort( b+L[q] , b+R[q]+1 ) ;
for( int i = p+1 ; i <= q-1 ; ++i )ad[i] += val ;
}
int ask( int l , int r , int val ){
int p = pos[l] , q = pos[r] , tot = 0 ;
if( p==q ){
for( int i = l ; i <= r ; ++i )if( a[i]+ad[p]>=val )tot++ ;
return tot ;
}
for( int i = l ; i <= R[p] ; ++i )if( a[i]+ad[p]>=val )tot++ ;//左边小区间
for( int i = L[q] ; i <= r ; ++i )if( a[i]+ad[q]>=val )tot++ ;//右边小区间
for( int i = p+1 ; i <= q-1 ; ++i )
tot += dx( L[i] , R[i] , val-ad[i] ) ;
return tot ;
}
int main(){
N = read() , M = read() , block = sqrt(N) ; int m1 , m2 , m3 , m4 ;
for( int i = 1 ; i <= N ; ++i )a[i] = read() ;
for( int i = 1 ; i <= block ; ++i )L[i] = (i-1)*block+1 , R[i] = block*i ;
if( R[block] < N )L[++block] = R[block-1]+1 , R[block] = N ;
for( int i = 1 ; i <= block ; ++i ){
for( int j = L[i] ; j <= R[i] ; ++j )pos[j] = i , b[j]=a[j] ;
sort( b+L[i] , b+R[i]+1 ) ;
}
while( M-- ){
m1 = getc() , m2 = read() , m3 = read() , m4 = read() ;
if( m1 )printf("%d\n",ask( m2 , m3 , m4 )) ;
else add( m2 , m3 , m4 ) ;
/*for( int i = 1 ; i <= N ; ++i )cout<<ad[pos[i]]+a[i]<<" " ;cout<<"XXXX"<<endl ;
for( int i = 1 ; i <= block ; ++i ){
for( int j = L[i] ; j <= R[i] ; ++j )cout<<b[j]+ad[pos[j]]<<" " ;cout<<" " ;
}
cout<<endl<<endl ;*/
}
return 0 ;
}
by 俾斯麦 @ 2019-10-17 15:04:07
对了,我隐去的那部分检验代码也和洛谷IDE输出不一致。
by kkksx @ 2019-10-17 15:04:28
正常操作
by zhengrunzhe @ 2019-10-17 15:25:04
if( R[block] < N )L[++block] = R[block-1]+1 , R[block] = N ;
这边由于不同系统的运算顺序不同 ++block放外面比较稳
by 俾斯麦 @ 2019-10-17 16:16:12
@zhengrunzhe 刚刚不在。谢谢,是这个问题。
by kkksx @ 2019-10-17 16:16:33
@俾斯麦 之前我不是说过这个问题吗,自己不听话qwq
by 俾斯麦 @ 2019-10-17 16:18:09
@御坂20001号 您太强了,不过,您好像上次死的时候我没死吧(相逢是问候)