Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- vector<int> t[10];
- // some auxillary function, that returns sometimes 0, sometimes non-zero
- int auxillary (const vector<int> & v, int arg) {
- int result = 0;
- // <smth>
- // here may be anything, complex enough to stop optimizer
- for (size_t i=0; i<v.size(); ++i)
- if (arg <= v[i])
- ++result;
- // </smth>
- cout << "auxillary = " << result << endl;
- return result;
- }
- // some complex recursive function, that performs calls to auxillary()
- int query (int v, int tl, int tr, int lx, int rx, int arg) {
- if (lx > rx) return 0;
- // sometimes the recursion results in calling auxillary()
- if (tl == lx && rx == tr) {
- cout << "call auxillary (t[" << v << "], " << arg << "):" << endl;
- return auxillary (t[v], arg);
- }
- // <smth>
- // here might be any complex recursive calls, resulting in auxillary() calls
- int tm = (tl + tr) / 2;
- int ans1 = query (v*2, tl, tm, lx, min(rx,tm), arg);
- int ans2 = query (v*2+1, tm+1, tr, max(lx,tm+1), rx, arg);
- int ans = ans1 + ans2;
- // </smth>
- //cout << "query = " << ans << endl;
- // ^^^^^ UNCOMMENT THIS LINE TO MAKE THE PROGRAM WORK OK
- return ans;
- }
- int main() {
- t[9].push_back (456); // some data to make auxillary() return non-zero sometimes
- cout << "global ans = " << query (1, 0, 5, 1, 2, 123) << endl;
- // ^^^^^ SHOULD OUTPUT "1"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement