제출 #482266

#제출 시각아이디문제언어결과실행 시간메모리
482266uroskXOR (IZhO12_xor)C++14
100 / 100
142 ms46344 KiB
// __builtin_popcount(x) broj bitova // __builtin_popcountll(x) long long #define here cerr<<"---------------------------\n" #include "bits/stdc++.h" #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> #define ld double #define ll long long #define ull unsigned long long #define llinf 100000000000000000LL // 10^17 #define iinf 2000000000 // 2*10^9 #define pb push_back #define popb pop_back #define fi first #define sc second #define endl '\n' #define pii pair<int,int> #define pll pair<ll,ll> #define pld pair<ld,ld> #define sz(a) int(a.size()) #define all(a) a.begin(),a.end() #define rall(a) a.begin(),a.end(),greater<int>() #define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());} #define pi 3.14159265358979323846 using namespace std; using namespace __gnu_pbds; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; void setIO(string inoutname) { freopen((inoutname+".in").c_str(),"r",stdin); freopen((inoutname+".out").c_str(),"w",stdout); } #define maxn 250005 #define maxx 5000005 #define lg 31 ll n,x; ll a[maxn]; ll t[maxx][2]; ll col[maxx]; ll id = 1; void add(ll x,ll z){ ll i = 0; for(ll j = lg;j>=0;j--){ ll b = (1<<j)&x; if(b>0) b = 1; if(t[i][b]==0){ t[i][b] = id; col[id] = z; id++; } i = t[i][b]; col[i] = min(col[i],z); } } ll reshi(ll id){ ll y = a[id]; ll i = 0; ll ans = llinf; ll sum = 0; for(ll j = lg;j>=0;j--){ ll b = (1<<j)&y; ll c = (1<<j)&x; if(b>0) b = 1; if(c>0) c = 1; if(c){ if(t[i][!b]==0) break; i = t[i][!b]; }else{ if(t[i][!b]){ ans = min({ans,col[t[i][!b]],col[t[i][!b]]}); } if(t[i][b]==0) break; i = t[i][b]; } } if(ans==llinf) return -1; return ans; } void tc(){ //ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);; cin >> n >> x; for(ll i = 1;i<=n;i++){ cin >> a[i]; a[i] = a[i]^a[i-1]; } ll len = -1; ll j = -1; x--; for(ll i = 1;i<=n;i++){ if(a[i]>x){ len = i; j = 1; add(a[i],i); //cerr<<1<< " "<<i<<endl; continue; } ll j2 = reshi(i)+1; //cerr<<j2<< " "<<i<<endl; if(j2==0){ add(a[i],i); continue; } ll len2 = i-j2+1; if((a[i]^a[j2-1])>=x&&len2>len){ swap(len,len2); swap(j,j2); } add(a[i],i); } cout<<j<< " "<<len<<endl; } int main(){ ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0); //setIO("lol"); int t; t = 1; while(t--){ tc(); } return 0; } /* 4 6 6 1 2 4 out: 2 3 */

컴파일 시 표준 에러 (stderr) 메시지

xor.cpp: In function 'long long int reshi(long long int)':
xor.cpp:62:8: warning: unused variable 'sum' [-Wunused-variable]
   62 |     ll sum = 0;
      |        ^~~
xor.cpp: In function 'void setIO(std::string)':
xor.cpp:32:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |  freopen((inoutname+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
xor.cpp:33:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |      freopen((inoutname+".out").c_str(),"w",stdout);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...