I got this error while submitting my code in codeforces, I don't know about this error
Can anyone please help! I think this problem is related to some memory. It fails second test case which is not as large for getting a Runtime error!
'Diagnostics detected issues [cpp.clang++-diagnose]: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\vector:1802:10: runtime error: reference binding to null pointer of type 'std::_Simple_types::value_type' (aka 'int') SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\include\vector:1802:10 in'
And here is my code:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);
#define deci(n) fixed << setprecision(n)
#define test() int t;cin >> t;while (t--)
#define loop(i,a,n) for(int i=a;i<n;i++)
typedef vector<int> vi;
const int MOD = 1e9 + 7;
//********************THE END OF TEMPLATES*******************//
int main()
{
fast();
test()
{
int n,k;
cin>>n>>k;
vi arr(n,0);
loop(i,0,n)
{
cin>>arr[i];
}
vi peek_index_array;
loop(i,1,n-1)
{
if(arr[i]>arr[i-1] && arr[i]>arr[i+1])
peek_index_array.pb(i);
}
int max_peek=0;
int size=peek_index_array.size();
int total=1;
int right_index=0;
queue<int> peek_queue;
peek_queue.push(peek_index_array[0]);
loop(i,1,size)
{
if(peek_index_array[i]-peek_queue.front()<=k-3)
{
total++;
peek_queue.push(peek_index_array[i]);
}
else
{
if(total>max_peek)
{
max_peek=total;
right_index=peek_index_array[i-1];
}
while(!peek_queue.empty() && peek_index_array[i]-peek_queue.front()>k-3)
{
peek_queue.pop();
total--;
}
peek_queue.push(peek_index_array[i]);
total++;
}
}
// cout<<"total,max"<<total<<max_peek<<endl;
if(total>max_peek)
{
max_peek=total;
right_index=peek_index_array[size-1];
}
int left_index=right_index-k+3<=0? 1: right_index -k +3;
cout<<max_peek+1<<" "<<left_index<<endl;
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire